import time
from datetime import datetime
from lxml import etree


# 获取指定时间范围内的日期
def find_latest_date_in_range(date_list, start_date, end_date):
    # 将字符串日期转换为datetime对象
    date_objects = [datetime.strptime(date_str, '%Y-%m-%d') for date_str in date_list]
    start_obj = datetime.strptime(start_date, '%Y-%m-%d')
    end_obj = datetime.strptime(end_date, '%Y-%m-%d')

    # 筛选时间范围内的日期
    filtered_dates = [date for date in date_objects if start_obj <= date <= end_obj]

    # 如果有符合条件的日期，返回所有符合条件的日期（格式化为字符串）
    if filtered_dates:
        return [date.strftime('%Y-%m-%d') for date in filtered_dates]
    else:
        print(f"{start_date} 00:00:00-{end_date} 00:00:00无体检记录")
        return []
def tijiandownload(id_number,ehrid,headers_date,DOMAIN,start_time, end_time):
    url_date = f"{DOMAIN}/phis/app/svc/exam"


    data = {
        "search_EQ_ehrId": f"{ehrid}",
        "_dch": "1757572002132"
    }
    import requests
    response_date = requests.post(url=url_date, headers=headers_date, data=data)
    print(response_date.json())


    date_list = []

    for info in response_date.json():
        date_list.append(info["examDate"])
    print(date_list)
    target_date_list = find_latest_date_in_range(date_list, start_time, end_time)

    if target_date_list == []:
        return []

    print(target_date_list)
    all_infomation = []# 存储所有信息的列表
    list_riqibianshi = []# 用于处理有重复日期的数据
    try:
        for target_date in target_date_list:
            if target_date:
                for info in response_date.json():
                    tijian_data = {
                        "身份证号": f"'{id_number}",
                        "体检日期": None,
                        "体检机构": None,
                        "姓名": None,
                        "性别": None,
                        "出生日期": None,
                        "年龄": None,
                        "责任医生": None,
                        "所属人群": None,
                        "体检类型": None,
                        "下次体检日期": None,
                        "症状": None,
                        "症状其他编辑框": None,
                        "体温": None,
                        "脉率": None,
                        "呼吸频率": None,
                        "左侧血压(收缩压)": None,
                        "左侧血压(舒张压)": None,
                        "右侧血压(收缩压)": None,
                        "右侧血压(舒张压)": None,
                        "身高": None,
                        "体重": None,
                        "腰围": None,
                        "臀围": None,
                        "体质指数": None,
                        "腰臀比": None,
                        "老年人健康状态": None,
                        "老年人生活自理能力自我评估": None,
                        "老年人认知功能": None,
                        "老年人认知功能编辑框": None,
                        "老年人情感状态": None,
                        "老年人抑郁评分检查": None,
                        "锻炼频率": None,
                        "每次锻炼时间分钟": None,
                        "坚持锻炼时间年": None,
                        "锻炼方式": None,
                        "饮食习惯": None,
                        "吸烟状况": None,
                        "日吸烟量": None,
                        "开始吸烟年龄": None,
                        "戒烟年龄": None,
                        "饮酒状况": None,
                        "日饮酒量": None,
                        "是否戒酒": None,
                        "开始饮酒年龄": None,
                        "戒酒年龄": None,
                        "近一年内是否曾醉酒": None,
                        "饮酒种类": None,
                        "职业病危害因素接触史": None,
                        "工种": None,
                        "从业时间": None,
                        "粉尘": None,
                        "粉尘防护措施": None,
                        "粉尘防护措施详细信息": None,
                        "放射物质": None,
                        "放射物质防护措施": None,
                        "放射物质防护措施详细信息": None,
                        "物理因素": None,
                        "物理因素防护措施": None,
                        "物理因素防护措施详细信息": None,
                        "化学物质": None,
                        "化学物质防护措施": None,
                        "化学物质防护措施详细信息": None,
                        "其他": None,
                        "其他防护措施": None,
                        "其他防护措施详细信息": None,
                        "口唇": None,
                        "齿列": None,
                        "咽部": None,
                        "视力左眼": None,
                        "视力右眼": None,
                        "矫正视力左眼": None,
                        "矫正视力右眼": None,
                        "听力": None,
                        "运动功能": None,
                        "眼底": None,
                        "眼底编辑框": None,
                        "皮肤": None,
                        "皮肤编辑框": None,
                        "巩膜": None,
                        "巩膜编辑框": None,
                        "淋巴结": None,
                        "淋巴结编辑框": None,
                        "桶状胸": None,
                        "呼吸音": None,
                        "呼吸音编辑框": None,
                        "罗音": None,
                        "罗音编辑框": None,
                        "心率": None,
                        "心律": None,
                        "杂音": None,
                        "杂音编辑框": None,
                        "压痛": None,
                        "压痛编辑框": None,
                        "包块": None,
                        "包块编辑框": None,
                        "肝大": None,
                        "肝大编辑框": None,
                        "脾大": None,
                        "脾大编辑框": None,
                        "移动性浊音": None,
                        "移动性浊音编辑框": None,
                        "下肢水肿": None,
                        "足背动脉搏动": None,
                        "肛门指诊": None,
                        "肛门指诊编辑框": None,
                        "乳腺": None,
                        "乳腺编辑框": None,
                        "外阴": None,
                        "外阴编辑框": None,
                        "阴道": None,
                        "阴道编辑框": None,
                        "宫颈": None,
                        "宫颈编辑框": None,
                        "宫体": None,
                        "宫体编辑框": None,
                        "附件": None,
                        "附件编辑框": None,
                        "宫颈涂片其他": None,
                        "血红蛋白": None,
                        "白细胞": None,
                        "血小板": None,
                        "血常规其他": None,
                        "尿蛋白": None,
                        "尿糖": None,
                        "尿酮体": None,
                        "尿潜血": None,
                        "尿常规其他": None,
                        "空腹血糖 (mmol/L)": None,
                        "空腹血糖 (mg/dL)": None,
                        "心电图": None,
                        "心电图编辑框": None,
                        "尿微量白蛋白": None,
                        "大便潜血": None,
                        "糖化血红蛋白": None,
                        "乙型肝炎": None,
                        "血清谷丙转氨酶": None,
                        "血清谷草转氨酶": None,
                        "白蛋白": None,
                        "总胆红素": None,
                        "结合胆红素": None,
                        "血清肌酐": None,
                        "血尿素氮": None,
                        "血钾浓度": None,
                        "血钠浓度": None,
                        "总胆固醇": None,
                        "甘油三酯": None,
                        "血清低密度脂蛋白胆固醇": None,
                        "血清高密度脂蛋白胆固醇": None,
                        "胸部X线片": None,
                        "胸部X线片编辑框": None,
                        "腹部B超": None,
                        "腹部B超编辑框": None,
                        "腹部B超其他": None,
                        "腹部B超其他编辑框": None,
                        "宫颈涂片": None,
                        "宫颈涂片编辑框": None,
                        "辅助检查其他": None,
                        "是否糖尿病": None,
                        "是否老年人": None,
                        "是否咳嗽、咳痰≥2周": None,
                        "是否痰中带血或咯血": None,
                        "脑血管疾病": None,
                        "脑血管疾病编辑框": None,
                        "肾脏疾病": None,
                        "肾脏疾病编辑框": None,
                        "心脏疾病": None,
                        "心脏疾病编辑框": None,
                        "血管疾病": None,
                        "血管疾病编辑框": None,
                        "眼部疾病": None,
                        "眼部疾病编辑框": None,
                        "神经系统疾病": None,
                        "神经系统疾病编辑框": None,
                        "其他系统疾病": None,
                        "其他系统疾病编辑框": None,
                        "评价": None,
                        "评价编辑框": None,
                        "指导": None,
                        "危险因素控制": None,
                        "减体重(kg)目标编辑框": None,
                        "减腰围(cm)目标编辑框": None,
                        "建议接种疫苗编辑框": None,
                        "危险因素控制其他编辑框": None,
                        "建议编辑框": None,
                        "药物名称": None
                    }

                    if info["examDate"] == target_date:
                        print("有信息")
                        # 体检类型
                        tjlx = []
                        list_tjlx = [("tpHealth","健康体检"),("tpOld","老年人体检"),("tpHypertension","高血压体检"),("tpDiabetesMellitus","糖尿病体检"),("tpCerebralApoplexy","脑卒中体检"),("tpCoronaryDisease","冠心病体检"),("tpMentalDisorder","精神病体检"),("tpHandicapped","残疾人体检")]
                        for tjlx_item in list_tjlx:
                            try:
                                tijianleixing = int(info.get(tjlx_item[0]))
                                if tijianleixing == 1:
                                    tjlx.append(tjlx_item[1])
                                else:
                                    pass
                            except Exception as e:
                                tjlx.append("获取失败")
                        tijian_data["体检类型"] = ",".join(tjlx)
                        print("获取的体检类型为:",tijian_data["体检类型"])


                        # 体检机构
                        tijian_data["体检机构"] = info.get("examOrgName")
                        print("体检机构:",tijian_data["体检机构"])
                        # 症状
                        zhengzhuangliebiao = [
                            "无症状",
                            "头痛",
                            "头晕",
                            "心悸",
                            "胸闷",
                            "胸痛",
                            "慢性咳嗽",
                            "咳痰",
                            "呼吸困难",
                            "多饮",
                            "多尿",
                            "体重下降",
                            "乏力",
                            "关节肿痛",
                            "视力模糊",
                            "手脚麻木",
                            "尿急",
                            "尿痛",
                            "便秘",
                            "腹泻",
                            "恶心呕吐",
                            "眼花",
                            "耳鸣",
                            "乳房胀痛",
                            "其他"
                        ]

                        riqi_id = info.get("id", None)
                        # 处理重复日期的数据
                        if riqi_id in list_riqibianshi:
                            continue
                        list_riqibianshi.append(riqi_id)

                        try:
                            zz_str = info.get("examSymptom")
                            zz_list = [zhengzhuangliebiao[int(zz)-1] for zz in zz_str.split(",")]
                        except:
                            zz_list = ["获取失败"]
                        tijian_data["症状"] = ",".join(zz_list)
                        tijian_data["证状其他编辑框"] = info.get("symptomDes",None)
                        if tijian_data["证状其他编辑框"] == "未查":
                            tijian_data["证状其他编辑框"] = ""
                        print("症状其他编辑框:",tijian_data["证状其他编辑框"])
                        if "其他" in tijian_data["症状"]:
                            tijian_data["症状"] = tijian_data["症状"].replace("其他",f"其他: {tijian_data['证状其他编辑框']}")
                            tijian_data["症状"] = tijian_data["症状"].strip(",")
                        print("症状:",tijian_data["症状"])


                        # 吸烟状况
                        try:
                            xiyanzhuangkuang = info.get("examSmSmoking",None)
                            if xiyanzhuangkuang == "1":
                                tijian_data["吸烟状况"] = "从不吸烟"
                                tijian_data["日吸烟量"] = None
                                tijian_data["开始吸烟年龄"] = None
                                tijian_data["戒烟年龄"] = None
                            elif xiyanzhuangkuang == "2":
                                tijian_data["吸烟状况"] = "已戒烟"
                                tijian_data["日吸烟量"] = info.get("examSmCount",None)
                                tijian_data["开始吸烟年龄"] = info.get("examSmStartAge",None)
                                tijian_data["戒烟年龄"] = info.get("examSmEndAge",None)
                            elif xiyanzhuangkuang == "3":
                                tijian_data["吸烟状况"] = "吸烟"
                                tijian_data["日吸烟量"] = info.get("examSmCount",None)
                                tijian_data["开始吸烟年龄"] = info.get("examSmStartAge",None)
                                tijian_data["戒烟年龄"] = None
                            else:
                                tijian_data["吸烟状况"] = None
                                tijian_data["日吸烟量"] = None
                                tijian_data["开始吸烟年龄"] = None
                                tijian_data["戒烟年龄"] = None
                        except:
                            tijian_data["吸烟状况"] = "获取错误"
                            tijian_data["日吸烟量"] = "获取错误"
                            tijian_data["开始吸烟年龄"] = "获取错误"
                            tijian_data["戒烟年龄"] = "获取错误"
                        print("吸烟状况:",tijian_data["吸烟状况"])
                        print("日吸烟量:",tijian_data["日吸烟量"])
                        print("开始吸烟年龄:",tijian_data["开始吸烟年龄"])
                        print("戒烟年龄:",tijian_data["戒烟年龄"])


                        # 饮酒状况
                        yinjiuzhonglei = ["白酒","啤酒","红酒","黄酒","其他"]
                        try:
                            xiyanzhuangkuang = info.get("examDkCycle",None)
                            if xiyanzhuangkuang == "1":
                                tijian_data["饮酒状况"] = "从不"
                                tijian_data["日饮酒量"] = None
                                tijian_data["是否戒酒"] = None
                                tijian_data["开始饮酒年龄"] = None
                                tijian_data["戒酒年龄"] = None
                                tijian_data["近一年内是否曾醉酒"] = None
                                tijian_data["饮酒种类"] = None
                            elif xiyanzhuangkuang == "2":
                                tijian_data["饮酒状况"] = "偶尔"
                                tijian_data["日饮酒量"] = info.get("examDkCount",None)
                                tijian_data["是否戒酒"] = info.get("examDkEnd",None)
                                if tijian_data["是否戒酒"] == "1":
                                    tijian_data["是否戒酒"] = "未戒酒"
                                    tijian_data["戒酒年龄"] = None
                                elif tijian_data["是否戒酒"] == "2":
                                    tijian_data["是否戒酒"] = "已戒酒"
                                    tijian_data["戒酒年龄"] = info.get("examDkEndAge",None)
                                else:
                                    tijian_data["戒酒年龄"] = None

                                tijian_data["开始饮酒年龄"] = info.get("examDkStartAge",None)

                                tijian_data["近一年内是否曾醉酒"] = info.get("examDkDrunkenness",None)
                                if tijian_data["近一年内是否曾醉酒"] == "1":
                                    tijian_data["近一年内是否曾醉酒"] = "是"
                                elif tijian_data["近一年内是否曾醉酒"] == "2":
                                    tijian_data["近一年内是否曾醉酒"] = "否"

                                zhonglei = info.get("examDkKind",None)
                                if zhonglei != None:
                                    yinjiu_list = [yinjiuzhonglei[int(yjzl) - 1] for yjzl in zhonglei.split(",")]
                                    tijian_data["饮酒种类"] = ", ".join(yinjiu_list)
                                else:
                                    tijian_data["饮酒种类"] = None
                                yinjiuleixing_qita = info.get("examDkKindDes",None)
                                if yinjiuleixing_qita != None:
                                    tijian_data["饮酒种类"] = tijian_data["饮酒种类"] + '：' + yinjiuleixing_qita


                            elif xiyanzhuangkuang == "3":
                                tijian_data["饮酒状况"] = "经常"
                                tijian_data["日饮酒量"] = info.get("examDkCount", None)
                                tijian_data["是否戒酒"] = info.get("examDkEnd", None)
                                if tijian_data["是否戒酒"] == "1":
                                    tijian_data["是否戒酒"] = "未戒酒"
                                    tijian_data["戒酒年龄"] = None
                                elif tijian_data["是否戒酒"] == "2":
                                    tijian_data["是否戒酒"] = "已戒酒"
                                    tijian_data["戒酒年龄"] = info.get("examDkEndAge", None)
                                else:
                                    tijian_data["戒酒年龄"] = None

                                tijian_data["开始饮酒年龄"] = info.get("examDkStartAge", None)

                                tijian_data["近一年内是否曾醉酒"] = info.get("examDkDrunkenness", None)
                                if tijian_data["近一年内是否曾醉酒"] == "1":
                                    tijian_data["近一年内是否曾醉酒"] = "是"
                                elif tijian_data["近一年内是否曾醉酒"] == "2":
                                    tijian_data["近一年内是否曾醉酒"] = "否"

                                zhonglei = info.get("examDkKind", None)
                                if zhonglei != None:
                                    yinjiu_list = [yinjiuzhonglei[int(yjzl) - 1] for yjzl in zhonglei.split(",")]
                                    tijian_data["饮酒种类"] = ", ".join(yinjiu_list)
                                else:
                                    tijian_data["饮酒种类"] = None
                                yinjiuleixing_qita = info.get("examDkKindDes", None)
                                if yinjiuleixing_qita != None:
                                    tijian_data["饮酒种类"] = tijian_data["饮酒种类"] + '：' + yinjiuleixing_qita

                            elif xiyanzhuangkuang == "4":
                                tijian_data["饮酒状况"] = "每天"
                                tijian_data["日饮酒量"] = info.get("examDkCount", None)
                                tijian_data["是否戒酒"] = info.get("examDkEnd", None)
                                if tijian_data["是否戒酒"] == "1":
                                    tijian_data["是否戒酒"] = "未戒酒"
                                    tijian_data["戒酒年龄"] = None
                                elif tijian_data["是否戒酒"] == "2":
                                    tijian_data["是否戒酒"] = "已戒酒"
                                    tijian_data["戒酒年龄"] = info.get("examDkEndAge", None)
                                else:
                                    tijian_data["戒酒年龄"] = None

                                tijian_data["开始饮酒年龄"] = info.get("examDkStartAge", None)

                                tijian_data["近一年内是否曾醉酒"] = info.get("examDkDrunkenness", None)
                                if tijian_data["近一年内是否曾醉酒"] == "1":
                                    tijian_data["近一年内是否曾醉酒"] = "是"
                                elif tijian_data["近一年内是否曾醉酒"] == "2":
                                    tijian_data["近一年内是否曾醉酒"] = "否"

                                zhonglei = info.get("examDkKind", None)
                                if zhonglei != None:
                                    yinjiu_list = [yinjiuzhonglei[int(yjzl) - 1] for yjzl in zhonglei.split(",")]
                                    tijian_data["饮酒种类"] = ", ".join(yinjiu_list)
                                else:
                                    tijian_data["饮酒种类"] = None
                                yinjiuleixing_qita = info.get("examDkKindDes", None)
                                if yinjiuleixing_qita != None:
                                    tijian_data["饮酒种类"] = tijian_data["饮酒种类"] + '：' + yinjiuleixing_qita

                            else:
                                tijian_data["饮酒状况"] = None
                                tijian_data["日饮酒量"] = None
                                tijian_data["是否戒酒"] = None
                                tijian_data["开始饮酒年龄"] = None
                                tijian_data["戒酒年龄"] = None
                                tijian_data["近一年内是否曾醉酒"] = None
                                tijian_data["饮酒种类"] = None
                        except:
                            print("获取体检信息错误")
                            tijian_data["饮酒状况"] = "获取错误"
                            tijian_data["日饮酒量"] = "获取错误"
                            tijian_data["是否戒酒"] = "获取错误"
                            tijian_data["开始饮酒年龄"] = "获取错误"
                            tijian_data["戒酒年龄"] = "获取错误"
                            tijian_data["近一年内是否曾醉酒"] = "获取错误"
                            tijian_data["饮酒种类"] = "获取错误"
                        print("饮酒状况:", tijian_data["饮酒状况"])
                        print("日饮酒量:", tijian_data["日饮酒量"])
                        print("是否戒酒:", tijian_data["是否戒酒"])
                        print("开始饮酒年龄:", tijian_data["开始饮酒年龄"])
                        print("戒酒年龄:", tijian_data["戒酒年龄"])
                        print("近一年内是否曾醉酒:", tijian_data["近一年内是否曾醉酒"])
                        print("饮酒种类:", tijian_data["饮酒种类"])

                        # 职业病危害因素接触史
                        tijian_data["职业病危害因素接触史"] = info.get("examRisk", None)
                        if tijian_data["职业病危害因素接触史"] == "2":
                            tijian_data["职业病危害因素接触史"] = "有"
                            tijian_data["工种"] = info.get("examRiskWork", None)
                            tijian_data["从业时间"] = info.get("examRiskYear", None)
                            zhiyebinghuizong = [("粉尘","examRDust","examRDustG","examRDustGD"),("放射物质","examRRadiogen","examRRadiogenG","examRRadiogenGD"),("物理因素","examRPhysical","examRPhysicalG","examRPhysicalGD"),("化学物质","examRChemical","examRChemicalG","examRChemicalGD"),("其他","examROther","examROtherG","examROtherGD")]
                            for zhiyebing in zhiyebinghuizong:
                                tijian_data[zhiyebing[0]] = info.get(zhiyebing[1],None)
                                if tijian_data[zhiyebing[0]] == "":
                                    fanghucuoshi = info.get(zhiyebing[3],None)
                                    if fanghucuoshi == "1":
                                        tijian_data[zhiyebing[0]+"防护措施"] = "无"
                                        tijian_data[zhiyebing[0]+"防护措施"+"详细信息"] = None
                                    else:
                                        tijian_data[zhiyebing[0] + "防护措施"] = "有"
                                        tijian_data[zhiyebing[0] + "防护措施" + "详细信息"] = info.get(zhiyebing[3], None)
                                else:
                                    fanghucuoshi = info.get(zhiyebing[2],None)
                                    if fanghucuoshi == "1":
                                        tijian_data[zhiyebing[0]+"防护措施"] = "无"
                                        tijian_data[zhiyebing[0]+"防护措施"+"详细信息"] = None
                                    elif fanghucuoshi == "2":
                                        tijian_data[zhiyebing[0]+"防护措施"] = "有"
                                        tijian_data[zhiyebing[0]+"防护措施"+"详细信息"] = info.get(zhiyebing[3],None)
                                    else:
                                        tijian_data[zhiyebing[0]+"防护措施"] = "无"
                                        tijian_data[zhiyebing[0]+"防护措施"+"详细信息"] = None
                        else:
                            tijian_data["职业病危害因素接触史"] = "无"

                        print("职业病危害因素接触史:",tijian_data["职业病危害因素接触史"])
                        print("工种:",tijian_data["工种"])
                        print("从业时间:",tijian_data["从业时间"])
                        print("粉尘:",tijian_data["粉尘"])
                        print("粉尘防护措施:",tijian_data["粉尘防护措施"])
                        print("粉尘防护措施详细信息:",tijian_data["粉尘防护措施详细信息"])
                        print("放射物质:",tijian_data["放射物质"])
                        print("放射物质防护措施:",tijian_data["放射物质防护措施"])
                        print("放射物质防护措施详细信息:",tijian_data["放射物质防护措施详细信息"])
                        print("物理因素:",tijian_data["物理因素"])
                        print("物理因素防护措施:",tijian_data["物理因素防护措施"])
                        print("物理因素防护措施详细信息:",tijian_data["物理因素防护措施详细信息"])
                        print("化学物质:",tijian_data["化学物质"])
                        print("化学物质防护措施:",tijian_data["化学物质防护措施"])
                        print("化学物质防护措施详细信息:",tijian_data["化学物质防护措施详细信息"])
                        print("其他:",tijian_data["其他"])
                        print("其他防护措施:",tijian_data["其他防护措施"])
                        print("其他防护措施详细信息:",tijian_data["其他防护措施详细信息"])

                        # 药物id码
                        yaowu_id = info.get("examCode", None)

                        # 药物名称
                        import requests
                        params = {
                            'search_EQ_examCode': f'{yaowu_id}',
                        }
                        data = {
                            '_dch': str(time.time()).replace(".", "")[:13],
                        }
                        response = requests.post(
                            F'{DOMAIN}/phis/app/svc/exTakeMed',
                            params=params,
                            headers=headers_date,
                            data=data,
                            verify=False,
                        )
                        all_yongyao = []
                        for yongyao in response.json()['content']:
                            yongyao_dict = {}
                            yongyao_dict["药物名称"] = yongyao.get("medName", '')
                            yongyao_dict["用法"] = yongyao.get("methodVolume", '')
                            yongyao_dict["用量"] = yongyao.get("useLevel", '')
                            yongyao_dict["备注"] = yongyao.get("remark", '')
                            yongyao_dict["用药时间"] = str(yongyao.get("howLong", ''))
                            yongyaodanwei = yongyao.get("howLongUnit", '')
                            if yongyaodanwei == "1":
                                yongyao_dict["时间单位"] = "年"
                            elif yongyaodanwei == "2":
                                yongyao_dict["时间单位"] = "月"
                            elif yongyaodanwei == "3":
                                yongyao_dict["时间单位"] = "天"
                            else:
                                yongyao_dict["时间单位"] = "没有获取到"
                            fuyaoyicongxing = yongyao.get("compliance", '')
                            if fuyaoyicongxing == "1":
                                yongyao_dict["服药依从性"] = "规律"
                            elif fuyaoyicongxing == "2":
                                yongyao_dict["服药依从性"] = "间断"
                            elif fuyaoyicongxing == "3":
                                yongyao_dict["服药依从性"] = "不服药"
                            elif fuyaoyicongxing == "4":
                                yongyao_dict["服药依从性"] = "不详"
                            else:
                                yongyao_dict["服药依从性"] = "没有获取到"
                            all_yongyao.append(yongyao_dict)
                        tijian_data["药物名称"] = all_yongyao
                        if tijian_data["药物名称"] == []:
                            tijian_data["药物名称"] = None

                        print("药物名称:",tijian_data["药物名称"])



                        # 网页解析部分
                        url_txt = f"{DOMAIN}/phis/app/svc/exam/update/{riqi_id}"
                        response_text = requests.get(url_txt, headers=headers_date, verify=False)
                        tree = etree.HTML(response_text.text)
                        # 体检日期
                        # 从HTML中提取体检日期并赋值给tijian_data
                        try:
                            # 使用XPath查找具有特定id的input标签
                            exam_date_input = tree.xpath('//input[@id="EXAM1.examDate"]')[0]
                            # 获取value属性值
                            exam_date_value = exam_date_input.get('value')
                            # 赋值给tijian_data字典
                            tijian_data["体检日期"] = exam_date_value
                        except Exception as e:
                            tijian_data["体检日期"] = "获取失败"

                        print("体检日期:", tijian_data["体检日期"])

                        # 责任医生
                        try:
                            # 使用XPath查找具有特定name属性的input标签
                            duty_doctor_input = tree.xpath('//input[@name="EXAM1.dutyDoctor"]')[0]
                            # 获取value属性值
                            duty_doctor_value = duty_doctor_input.get('value')
                            # 赋值给tijian_data字典
                            tijian_data["责任医生"] = duty_doctor_value
                        except Exception as e:
                            tijian_data["责任医生"] = "获取失败"

                        print("责任医生:", tijian_data["责任医生"])

                        # 姓名、性别、出生日期、年龄、所属人群、下次体检日期
                        try:
                            # 姓名
                            name_input = tree.xpath('//td[@style="width:260px"]//input[@class="input_bottomLine_text_span"]')[0]
                            tijian_data["姓名"] = name_input.get('value')
                        except Exception as e:
                            tijian_data["姓名"] = "获取失败"

                        try:
                            # 性别
                            gender_input = tree.xpath('//input[@id="examGender"]')[0]
                            tijian_data["性别"] = gender_input.get('value')
                        except Exception as e:
                            tijian_data["性别"] = "获取失败"

                        try:
                            # 出生日期
                            birth_date_input = tree.xpath('//input[@id="birthDate"]')[0]
                            tijian_data["出生日期"] = birth_date_input.get('value')
                        except Exception as e:
                            tijian_data["出生日期"] = "获取失败"

                        try:
                            # 年龄
                            age_input = tree.xpath('//input[@id="examAge"]')[0]
                            tijian_data["年龄"] = age_input.get('value')
                        except Exception as e:
                            tijian_data["年龄"] = "获取失败"

                        try:
                            # 所属人群
                            crowd_input = tree.xpath('//input[@class="input_bottomLine_text_span" and @readonly="readonly" and @style="width:400px"]')[0]
                            tijian_data["所属人群"] = crowd_input.get('value')
                        except Exception as e:
                            tijian_data["所属人群"] = "获取失败"

                        try:
                            # 下次体检日期
                            next_exam_date_input = tree.xpath('//input[@id="EXAM1.nextExamDate"]')[0]
                            tijian_data["下次体检日期"] = next_exam_date_input.get('value')
                        except Exception as e:
                            tijian_data["下次体检日期"] = "获取失败"

                        print("姓名:", tijian_data["姓名"])
                        print("性别:", tijian_data["性别"])
                        print("出生日期:", tijian_data["出生日期"])
                        print("年龄:", tijian_data["年龄"])
                        print("所属人群:", tijian_data["所属人群"])
                        print("下次体检日期:", tijian_data["下次体检日期"])

                        # 体温、脉率、呼吸频率、血压、身高、体重、腰围、臀围、体质指数、腰臀比
                        try:
                            # 体温
                            temperature_input = tree.xpath('//input[@id="EXAM1.temperature"]')[0]
                            tijian_data["体温"] = temperature_input.get('value')
                        except Exception as e:
                            tijian_data["体温"] = "获取失败"

                        try:
                            # 脉率
                            pulse_input = tree.xpath('//input[@id="EXAM1.pulse"]')[0]
                            tijian_data["脉率"] = pulse_input.get('value')
                        except Exception as e:
                            tijian_data["脉率"] = "获取失败"

                        try:
                            # 呼吸频率
                            breathing_input = tree.xpath('//input[@id="EXAM1.breathing"]')[0]
                            tijian_data["呼吸频率"] = breathing_input.get('value')
                        except Exception as e:
                            tijian_data["呼吸频率"] = "获取失败"

                        try:
                            # 左侧血压(收缩压)
                            sbpL_input = tree.xpath('//input[@id="EXAM1.sbpL"]')[0]
                            tijian_data["左侧血压(收缩压)"] = sbpL_input.get('value')
                        except Exception as e:
                            tijian_data["左侧血压(收缩压)"] = "获取失败"

                        try:
                            # 左侧血压(舒张压)
                            dbpL_input = tree.xpath('//input[@id="EXAM1.dbpL"]')[0]
                            tijian_data["左侧血压(舒张压)"] = dbpL_input.get('value')
                        except Exception as e:
                            tijian_data["左侧血压(舒张压)"] = "获取失败"

                        try:
                            # 右侧血压(收缩压)
                            sbpR_input = tree.xpath('//input[@id="EXAM1.sbpR"]')[0]
                            tijian_data["右侧血压(收缩压)"] = sbpR_input.get('value')
                        except Exception as e:
                            tijian_data["右侧血压(收缩压)"] = "获取失败"

                        try:
                            # 右侧血压(舒张压)
                            dbpR_input = tree.xpath('//input[@id="EXAM1.dbpR"]')[0]
                            tijian_data["右侧血压(舒张压)"] = dbpR_input.get('value')
                        except Exception as e:
                            tijian_data["右侧血压(舒张压)"] = "获取失败"

                        try:
                            # 身高
                            height_input = tree.xpath('//input[@id="EXAM1.height"]')[0]
                            tijian_data["身高"] = height_input.get('value')
                        except Exception as e:
                            tijian_data["身高"] = "获取失败"

                        try:
                            # 体重
                            weight_input = tree.xpath('//input[@id="EXAM1.weight"]')[0]
                            tijian_data["体重"] = weight_input.get('value')
                        except Exception as e:
                            tijian_data["体重"] = "获取失败"

                        try:
                            # 腰围
                            waistline_input = tree.xpath('//input[@id="EXAM1.waistline"]')[0]
                            tijian_data["腰围"] = waistline_input.get('value')
                        except Exception as e:
                            tijian_data["腰围"] = "获取失败"

                        try:
                            # 臀围
                            hipline_input = tree.xpath('//input[@id="EXAM1.hipline"]')[0]
                            tijian_data["臀围"] = hipline_input.get('value')
                        except Exception as e:
                            tijian_data["臀围"] = "获取失败"

                        try:
                            # 体质指数
                            bmi_input = tree.xpath('//input[@id="EXAM1.bmi"]')[0]
                            tijian_data["体质指数"] = bmi_input.get('value')
                        except Exception as e:
                            tijian_data["体质指数"] = "获取失败"

                        try:
                            # 腰臀比
                            whr_input = tree.xpath('//input[@id="EXAM1.whr"]')[0]
                            tijian_data["腰臀比"] = whr_input.get('value')
                        except Exception as e:
                            tijian_data["腰臀比"] = "获取失败"

                        print("体温:", tijian_data["体温"])
                        print("脉率:", tijian_data["脉率"])
                        print("呼吸频率:", tijian_data["呼吸频率"])
                        print("左侧血压(收缩压):", tijian_data["左侧血压(收缩压)"])
                        print("左侧血压(舒张压):", tijian_data["左侧血压(舒张压)"])
                        print("右侧血压(收缩压):", tijian_data["右侧血压(收缩压)"])
                        print("右侧血压(舒张压):", tijian_data["右侧血压(舒张压)"])
                        print("身高:", tijian_data["身高"])
                        print("体重:", tijian_data["体重"])
                        print("腰围:", tijian_data["腰围"])
                        print("臀围:", tijian_data["臀围"])
                        print("体质指数:", tijian_data["体质指数"])
                        print("腰臀比:", tijian_data["腰臀比"])




                        # 老年人健康状态
                        # 老年人健康状态	老年人生活自理能力自我评估	老年人认知功能	老年人认知功能编辑框	老年人情感状态	老年人抑郁评分检查
                        if "老年人体检" in tijian_data["体检类型"]:
                            # 获取老年人健康状态
                            try:
                                exam_old_health_inputs = tree.xpath('//input[@name="EXAM1.examOldHealth"]')
                                for input_elem in exam_old_health_inputs:
                                    if 'checked' in input_elem.attrib:
                                        old_health_value = input_elem.get('value')
                                        old_health_dict = {
                                            "1": "满意",
                                            "2": "基本满意",
                                            "3": "说不清楚",
                                            "4": "不太满意",
                                            "5": "不满意"
                                        }
                                        tijian_data["老年人健康状态"] = old_health_dict.get(old_health_value,
                                                                                            "获取失败")
                                        break
                                else:
                                    tijian_data["老年人健康状态"] = "获取失败"
                            except Exception as e:
                                tijian_data["老年人健康状态"] = "获取失败"

                            print("老年人健康状态:", tijian_data["老年人健康状态"])
                            # 老年人生活自理能力自我评估
                            # 获取老年人生活自理能力自我评估
                            try:
                                exam_old_self_help_inputs = tree.xpath('//input[@name="EXAM1.examOldSelfHelp"]')
                                for input_elem in exam_old_self_help_inputs:
                                    if 'checked' in input_elem.attrib:
                                        old_self_help_value = input_elem.get('value')
                                        old_self_help_dict = {
                                            "1": "可 自 理（0～3分）",
                                            "2": "轻度依赖（4～8分）",
                                            "3": "中度依赖（9～18分）",
                                            "4": "不能自理（≥19分）"
                                        }
                                        tijian_data["老年人生活自理能力自我评估"] = old_self_help_dict.get(
                                            old_self_help_value, "获取失败")
                                        break
                                else:
                                    tijian_data["老年人生活自理能力自我评估"] = "获取失败"
                            except Exception as e:
                                tijian_data["老年人生活自理能力自我评估"] = "获取失败"

                            print("老年人生活自理能力自我评估:", tijian_data["老年人生活自理能力自我评估"])
                            # 获取老年人认知功能 老年人认知功能编辑框
                            try:
                                exam_old_cognivite_inputs = tree.xpath('//input[@name="EXAM1.examOldCognivite"]')
                                for input_elem in exam_old_cognivite_inputs:
                                    if 'checked' in input_elem.attrib:
                                        old_cognivite_value = input_elem.get('value')
                                        old_cognivite_dict = {
                                            "1": "粗筛阴性",
                                            "2": "粗筛阳性"
                                        }
                                        tijian_data["老年人认知功能"] = old_cognivite_dict.get(old_cognivite_value, "获取失败")
                                        break
                                else:
                                    tijian_data["老年人认知功能"] = "获取失败"
                            except Exception as e:
                                tijian_data["老年人认知功能"] = "获取失败"

                            # 获取简易智力状态检查分数
                            try:
                                exam_old_iq_input = tree.xpath('//input[@id="examOldIq"]')[0]
                                tijian_data["老年人认知功能编辑框"] = exam_old_iq_input.get('value')
                            except Exception as e:
                                tijian_data["老年人认知功能编辑框"] = "获取失败"

                            print("老年人认知功能:", tijian_data["老年人认知功能"])
                            print("老年人认知功能编辑框:", tijian_data["老年人认知功能编辑框"])
                            #
                            # 获取老年人情感状态
                            try:
                                exam_old_emotion_inputs = tree.xpath('//input[@name="EXAM1.examOldEmotion"]')
                                for input_elem in exam_old_emotion_inputs:
                                    if 'checked' in input_elem.attrib:
                                        old_emotion_value = input_elem.get('value')
                                        old_emotion_dict = {
                                            "1": "粗筛阴性",
                                            "2": "粗筛阳性"
                                        }
                                        tijian_data["老年人情感状态"] = old_emotion_dict.get(old_emotion_value,
                                                                                             "获取失败")
                                        break
                                else:
                                    tijian_data["老年人情感状态"] = "获取失败"
                            except Exception as e:
                                tijian_data["老年人情感状态"] = "获取失败"

                            # 获取老年人抑郁评分检查分数
                            try:
                                exam_old_depression_input = tree.xpath('//input[@id="examOldDepression"]')[0]
                                tijian_data["老年人抑郁评分检查"] = exam_old_depression_input.get('value')
                            except Exception as e:
                                tijian_data["老年人抑郁评分检查"] = "获取失败"

                            print("老年人情感状态:", tijian_data["老年人情感状态"])
                            print("老年人抑郁评分检查:", tijian_data["老年人抑郁评分检查"])





                        # 锻炼频率、每次锻炼时间分钟、坚持锻炼时间年、锻炼方式、饮食习惯
                        try:
                            # 锻炼频率
                            exam_ex_cycle_inputs = tree.xpath('//input[@name="EXAM1.examExCycle"]')
                            for input_elem in exam_ex_cycle_inputs:
                                if 'checked' in input_elem.attrib:
                                    # 根据value值确定锻炼频率
                                    cycle_value = input_elem.get('value')
                                    cycle_dict = {
                                        "1": "每天",
                                        "2": "每周一次以上",
                                        "3": "偶尔",
                                        "4": "不锻炼"
                                    }
                                    tijian_data["锻炼频率"] = cycle_dict.get(cycle_value, "获取失败")
                                    break
                            else:
                                tijian_data["锻炼频率"] = "获取失败"
                        except Exception as e:
                            tijian_data["锻炼频率"] = "获取失败"

                        try:
                            # 每次锻炼时间分钟
                            exam_ex_time_input = tree.xpath('//input[@id="examExTime"]')[0]
                            tijian_data["每次锻炼时间分钟"] = exam_ex_time_input.get('value')
                        except Exception as e:
                            tijian_data["每次锻炼时间分钟"] = "获取失败"

                        try:
                            # 坚持锻炼时间年
                            exam_ex_insist_input = tree.xpath('//input[@id="examExInsist"]')[0]
                            tijian_data["坚持锻炼时间年"] = exam_ex_insist_input.get('value')
                        except Exception as e:
                            tijian_data["坚持锻炼时间年"] = "获取失败"

                        try:
                            # 锻炼方式
                            exam_ex_type_input = tree.xpath('//input[@id="examExType"]')[0]
                            tijian_data["锻炼方式"] = exam_ex_type_input.get('value')
                        except Exception as e:
                            tijian_data["锻炼方式"] = "获取失败"

                        try:
                            # 饮食习惯
                            exam_food_habit_inputs = tree.xpath('//input[@name="EXAM1.examFoodHabit"]')
                            food_habits = []
                            for input_elem in exam_food_habit_inputs:
                                if 'checked' in input_elem.attrib:
                                    # 根据value值确定饮食习惯
                                    habit_value = input_elem.get('value')
                                    habit_dict = {
                                        "1": "荤素均衡",
                                        "2": "荤食为主",
                                        "3": "素食为主",
                                        "4": "嗜盐",
                                        "5": "嗜油",
                                        "6": "嗜糖"
                                    }
                                    food_habits.append(habit_dict.get(habit_value, ""))

                            tijian_data["饮食习惯"] = ",".join(food_habits) if food_habits else None
                        except Exception as e:
                            tijian_data["饮食习惯"] = "获取失败"

                        print("锻炼频率:", tijian_data["锻炼频率"])
                        print("每次锻炼时间分钟:", tijian_data["每次锻炼时间分钟"])
                        print("坚持锻炼时间年:", tijian_data["坚持锻炼时间年"])
                        print("锻炼方式:", tijian_data["锻炼方式"])
                        print("饮食习惯:", tijian_data["饮食习惯"])


                        #
                        # 口腔、视力、听力、运动功能相关信息
                        try:
                            # 口唇
                            exam_lips_inputs = tree.xpath('//input[@name="EXAM2.examLips"]')
                            for input_elem in exam_lips_inputs:
                                if 'checked' in input_elem.attrib:
                                    lips_value = input_elem.get('value')
                                    lips_dict = {
                                        "0": "未检查",
                                        "1": "红润",
                                        "2": "苍白",
                                        "3": "发绀",
                                        "4": "皲裂",
                                        "5": "疱疹"
                                    }
                                    tijian_data["口唇"] = lips_dict.get(lips_value, "获取失败")
                                    break
                            else:
                                tijian_data["口唇"] = "获取失败"
                        except Exception as e:
                            tijian_data["口唇"] = "获取失败"

                        try:
                            # 齿列
                            exam_dentition_inputs = tree.xpath('//input[@name="EXAM2.examDentition"]')
                            dentition_list = []
                            for input_elem in exam_dentition_inputs:
                                if 'checked' in input_elem.attrib:
                                    dentition_value = input_elem.get('value')
                                    dentition_dict = {
                                        "1": "正常",
                                        "2": "缺齿",
                                        "3": "龋齿",
                                        "4": "义齿(假牙)"
                                    }
                                    dentition_list.append(dentition_dict.get(dentition_value, ""))

                            tijian_data["齿列"] = ",".join(dentition_list) if dentition_list else "获取失败"
                        except Exception as e:
                            tijian_data["齿列"] = "获取失败"

                        try:
                            # 咽部
                            exam_pharyngeal_inputs = tree.xpath('//input[@name="EXAM2.examPharyngeal"]')
                            for input_elem in exam_pharyngeal_inputs:
                                if 'checked' in input_elem.attrib:
                                    pharyngeal_value = input_elem.get('value')
                                    pharyngeal_dict = {
                                        "0": "未检查",
                                        "1": "无充血",
                                        "2": "充血",
                                        "3": "淋巴滤泡增生"
                                    }
                                    tijian_data["咽部"] = pharyngeal_dict.get(pharyngeal_value, "获取失败")
                                    break
                            else:
                                tijian_data["咽部"] = "获取失败"
                        except Exception as e:
                            tijian_data["咽部"] = "获取失败"

                        try:
                            # 视力左眼
                            exam_eyesight_l_input = tree.xpath('//input[@id="examEyesightL"]')[0]
                            tijian_data["视力左眼"] = exam_eyesight_l_input.get('value')
                        except Exception as e:
                            tijian_data["视力左眼"] = "获取失败"

                        try:
                            # 视力右眼
                            exam_eyesight_r_input = tree.xpath('//input[@id="examEyesightR"]')[0]
                            tijian_data["视力右眼"] = exam_eyesight_r_input.get('value')
                        except Exception as e:
                            tijian_data["视力右眼"] = "获取失败"

                        try:
                            # 矫正视力左眼
                            exam_eyesight_cl_input = tree.xpath('//input[@id="examEyesightCl"]')[0]
                            tijian_data["矫正视力左眼"] = exam_eyesight_cl_input.get('value')
                        except Exception as e:
                            tijian_data["矫正视力左眼"] = "获取失败"

                        try:
                            # 矫正视力右眼
                            exam_eyesight_cr_input = tree.xpath('//input[@id="examEyesightCr"]')[0]
                            tijian_data["矫正视力右眼"] = exam_eyesight_cr_input.get('value')
                        except Exception as e:
                            tijian_data["矫正视力右眼"] = "获取失败"

                        try:
                            # 听力
                            exam_listening_inputs = tree.xpath('//input[@name="EXAM2.examListening"]')
                            for input_elem in exam_listening_inputs:
                                if 'checked' in input_elem.attrib:
                                    listening_value = input_elem.get('value')
                                    listening_dict = {
                                        "0": "未检查",
                                        "1": "听见",
                                        "2": "听不清或无法听见"
                                    }
                                    tijian_data["听力"] = listening_dict.get(listening_value, "获取失败")
                                    break
                            else:
                                tijian_data["听力"] = "获取失败"
                        except Exception as e:
                            tijian_data["听力"] = "获取失败"

                        try:
                            # 运动功能
                            exam_motor_fun_inputs = tree.xpath('//input[@name="EXAM2.examMotorFun"]')
                            for input_elem in exam_motor_fun_inputs:
                                if 'checked' in input_elem.attrib:
                                    motor_fun_value = input_elem.get('value')
                                    motor_fun_dict = {
                                        "0": "未检查",
                                        "1": "可顺利完成",
                                        "2": "无法独立完成其中任何一个动作"
                                    }
                                    tijian_data["运动功能"] = motor_fun_dict.get(motor_fun_value, "获取失败")
                                    break
                            else:
                                tijian_data["运动功能"] = "获取失败"
                        except Exception as e:
                            tijian_data["运动功能"] = "获取失败"

                        print("口唇:", tijian_data["口唇"])
                        print("齿列:", tijian_data["齿列"])
                        print("咽部:", tijian_data["咽部"])
                        print("视力左眼:", tijian_data["视力左眼"])
                        print("视力右眼:", tijian_data["视力右眼"])
                        print("矫正视力左眼:", tijian_data["矫正视力左眼"])
                        print("矫正视力右眼:", tijian_data["矫正视力右眼"])
                        print("听力:", tijian_data["听力"])
                        print("运动功能:", tijian_data["运动功能"])

                        #
                        # 眼底、皮肤、巩膜、淋巴结等查体信息
                        try:
                            # 眼底
                            exam_eyeground_inputs = tree.xpath('//input[@name="EXAM2.examEyeground"]')
                            for input_elem in exam_eyeground_inputs:
                                if 'checked' in input_elem.attrib:
                                    eyeground_value = input_elem.get('value')
                                    eyeground_dict = {
                                        "0": "未检查",
                                        "1": "正常",
                                        "2": "异常",
                                        "3": "无"
                                    }
                                    tijian_data["眼底"] = eyeground_dict.get(eyeground_value, "获取失败")
                                    break
                            else:
                                tijian_data["眼底"] = "获取失败"

                            # 眼底异常描述
                            exam_eyeground_des_input = tree.xpath('//input[@id="examEyegroundDes"]')[0]
                            tijian_data["眼底编辑框"] = exam_eyeground_des_input.get('value')
                        except Exception as e:
                            tijian_data["眼底"] = "获取失败"
                            tijian_data["眼底编辑框"] = "获取失败"

                        try:
                            # 皮肤
                            exam_skin_inputs = tree.xpath('//input[@name="EXAM2.examSkin"]')
                            for input_elem in exam_skin_inputs:
                                if 'checked' in input_elem.attrib:
                                    skin_value = input_elem.get('value')
                                    skin_dict = {
                                        "0": "未检查",
                                        "1": "正常",
                                        "2": "潮红",
                                        "3": "苍白",
                                        "4": "发绀",
                                        "5": "黄染",
                                        "6": "色素沉着",
                                        "7": "其他",
                                        "8": "无"
                                    }
                                    tijian_data["皮肤"] = skin_dict.get(skin_value, "获取失败")
                                    break
                            else:
                                tijian_data["皮肤"] = "获取失败"

                            # 皮肤描述
                            exam_skin_des_input = tree.xpath('//input[@id="examSkinDes"]')[0]
                            if exam_skin_des_input.get('value') == "未查":
                                pifubianjikuang = None
                            else:
                                pifubianjikuang = exam_skin_des_input.get('value')
                            tijian_data["皮肤编辑框"] = pifubianjikuang
                        except Exception as e:
                            tijian_data["皮肤"] = "获取失败"
                            tijian_data["皮肤编辑框"] = "获取失败"

                        try:
                            # 巩膜
                            exam_sclera_inputs = tree.xpath('//input[@name="EXAM2.examSclera"]')
                            for input_elem in exam_sclera_inputs:
                                if 'checked' in input_elem.attrib:
                                    sclera_value = input_elem.get('value')
                                    sclera_dict = {
                                        "0": "未检查",
                                        "1": "正常",
                                        "2": "黄染",
                                        "3": "充血",
                                        "4": "其他",
                                        "5": "无"
                                    }
                                    tijian_data["巩膜"] = sclera_dict.get(sclera_value, "获取失败")
                                    break
                            else:
                                tijian_data["巩膜"] = "获取失败"

                            # 巩膜描述
                            exam_sclera_des_input = tree.xpath('//input[@id="examScleraDes"]')[0]
                            if exam_sclera_des_input.get('value') == "未查":
                                pifubianjikuang = None
                            else:
                                pifubianjikuang = exam_sclera_des_input.get('value')
                            tijian_data["巩膜编辑框"] = pifubianjikuang
                        except Exception as e:
                            tijian_data["巩膜"] = "获取失败"
                            tijian_data["巩膜编辑框"] = "获取失败"

                        try:
                            # 淋巴结
                            exam_lymph_inputs = tree.xpath('//input[@name="EXAM2.examLymph"]')
                            for input_elem in exam_lymph_inputs:
                                if 'checked' in input_elem.attrib:
                                    lymph_value = input_elem.get('value')
                                    lymph_dict = {
                                        "0": "未检查",
                                        "1": "未触及",
                                        "2": "锁骨上",
                                        "3": "腋窝",
                                        "4": "其他",
                                        "5": "无"
                                    }
                                    tijian_data["淋巴结"] = lymph_dict.get(lymph_value, "获取失败")
                                    break
                            else:
                                tijian_data["淋巴结"] = "获取失败"

                            # 淋巴结描述
                            exam_lymph_des_input = tree.xpath('//input[@id="examLymphDes"]')[0]
                            if exam_lymph_des_input.get('value') == "未查":
                                pifubianjikuang = None
                                tijian_data["淋巴结编辑框"] = pifubianjikuang
                            else:
                                tijian_data["淋巴结编辑框"] = exam_lymph_des_input.get('value')
                        except Exception as e:
                            tijian_data["淋巴结"] = "获取失败"
                            tijian_data["淋巴结编辑框"] = "获取失败"

                        try:
                            # 桶状胸
                            exam_barrel_chest_inputs = tree.xpath('//input[@name="EXAM2.examBarrelChest"]')
                            for input_elem in exam_barrel_chest_inputs:
                                if 'checked' in input_elem.attrib:
                                    barrel_chest_value = input_elem.get('value')
                                    barrel_chest_dict = {
                                        "0": "未检查",
                                        "1": "否",
                                        "2": "是",
                                        "3": "无"
                                    }
                                    tijian_data["桶状胸"] = barrel_chest_dict.get(barrel_chest_value, "获取失败")
                                    break
                            else:
                                tijian_data["桶状胸"] = "获取失败"
                        except Exception as e:
                            tijian_data["桶状胸"] = "获取失败"

                        try:
                            # 呼吸音
                            exam_breath_sd_inputs = tree.xpath('//input[@name="EXAM2.examBreathSd"]')
                            for input_elem in exam_breath_sd_inputs:
                                if 'checked' in input_elem.attrib:
                                    breath_sd_value = input_elem.get('value')
                                    breath_sd_dict = {
                                        "0": "未检查",
                                        "1": "正常",
                                        "2": "异常",
                                        "3": "无"
                                    }
                                    tijian_data["呼吸音"] = breath_sd_dict.get(breath_sd_value, "获取失败")
                                    break
                            else:
                                tijian_data["呼吸音"] = "获取失败"

                            # 呼吸音描述
                            exam_breath_sd_des_input = tree.xpath('//input[@id="examBreathSdDes"]')[0]
                            if exam_breath_sd_des_input.get('value') == "未查":
                                pifubianjikuang = None
                                tijian_data["呼吸音编辑框"] = pifubianjikuang
                            else:
                                tijian_data["呼吸音编辑框"] = exam_breath_sd_des_input.get('value')
                        except Exception as e:
                            tijian_data["呼吸音"] = "获取失败"
                            tijian_data["呼吸音编辑框"] = "获取失败"

                        try:
                            # 罗音
                            exam_rale_inputs = tree.xpath('//input[@name="EXAM2.examRale"]')
                            for input_elem in exam_rale_inputs:
                                if 'checked' in input_elem.attrib:
                                    rale_value = input_elem.get('value')
                                    rale_dict = {
                                        "0": "未检查",
                                        "1": "无",
                                        "2": "干罗音",
                                        "3": "湿罗音",
                                        "4": "其他"
                                    }
                                    tijian_data["罗音"] = rale_dict.get(rale_value, "获取失败")
                                    break
                            else:
                                tijian_data["罗音"] = "获取失败"

                            # 罗音描述
                            exam_rale_des_input = tree.xpath('//input[@id="examRaleDes"]')[0]
                            if exam_rale_des_input.get('value') == "未查":
                                pifubianjikuang = None
                                tijian_data["罗音编辑框"] = pifubianjikuang
                            else:
                                tijian_data["罗音编辑框"] = exam_rale_des_input.get('value')
                        except Exception as e:
                            tijian_data["罗音"] = "获取失败"
                            tijian_data["罗音编辑框"] = "获取失败"

                        try:
                            # 心率
                            exam_heart_rate_input = tree.xpath('//input[@id="EXAM2.examHeartRate"]')[0]
                            tijian_data["心率"] = exam_heart_rate_input.get('value')
                        except Exception as e:
                            tijian_data["心率"] = "获取失败"

                        try:
                            # 心律
                            exam_heart_rhythm_inputs = tree.xpath('//input[@name="EXAM2.examHeartRhythm"]')
                            for input_elem in exam_heart_rhythm_inputs:
                                if 'checked' in input_elem.attrib:
                                    heart_rhythm_value = input_elem.get('value')
                                    heart_rhythm_dict = {
                                        "0": "未检查",
                                        "1": "齐",
                                        "2": "不齐",
                                        "3": "绝对不齐",
                                        "4": "无"
                                    }
                                    tijian_data["心律"] = heart_rhythm_dict.get(heart_rhythm_value, "获取失败")
                                    break
                            else:
                                tijian_data["心律"] = "获取失败"
                        except Exception as e:
                            tijian_data["心律"] = "获取失败"

                        try:
                            # 杂音
                            exam_noise_inputs = tree.xpath('//input[@name="EXAM2.examNoise"]')
                            for input_elem in exam_noise_inputs:
                                if 'checked' in input_elem.attrib:
                                    noise_value = input_elem.get('value')
                                    noise_dict = {
                                        "0": "未检查",
                                        "1": "无",
                                        "2": "有"
                                    }
                                    tijian_data["杂音"] = noise_dict.get(noise_value, "获取失败")
                                    break
                            else:
                                tijian_data["杂音"] = "获取失败"

                            # 杂音描述
                            exam_noise_des_input = tree.xpath('//input[@id="examNoiseDes"]')[0]
                            if exam_noise_des_input.get('value') == "未查":
                                tijian_data["杂音编辑框"] = None
                            else:
                                tijian_data["杂音编辑框"] = exam_noise_des_input.get('value')
                        except Exception as e:
                            tijian_data["杂音"] = "获取失败"
                            tijian_data["杂音编辑框"] = "获取失败"

                        try:
                            # 压痛
                            exam_tenderness_inputs = tree.xpath('//input[@name="EXAM2.examTenderness"]')
                            for input_elem in exam_tenderness_inputs:
                                if 'checked' in input_elem.attrib:
                                    tenderness_value = input_elem.get('value')
                                    tenderness_dict = {
                                        "0": "未检查",
                                        "1": "无",
                                        "2": "有"
                                    }
                                    tijian_data["压痛"] = tenderness_dict.get(tenderness_value, "获取失败")
                                    break
                            else:
                                tijian_data["压痛"] = "获取失败"

                            # 压痛描述
                            exam_tenderness_des_input = tree.xpath('//input[@id="examTendernessDes"]')[0]
                            if exam_tenderness_des_input.get('value') == "未查":
                                tijian_data["压痛编辑框"] = None
                            else:
                                tijian_data["压痛编辑框"] = exam_tenderness_des_input.get('value')

                        except Exception as e:
                            tijian_data["压痛"] = "获取失败"
                            tijian_data["压痛编辑框"] = "获取失败"

                        try:
                            # 包块
                            exam_masses_inputs = tree.xpath('//input[@name="EXAM2.examMasses"]')
                            for input_elem in exam_masses_inputs:
                                if 'checked' in input_elem.attrib:
                                    masses_value = input_elem.get('value')
                                    masses_dict = {
                                        "0": "未检查",
                                        "1": "无",
                                        "2": "有"
                                    }
                                    tijian_data["包块"] = masses_dict.get(masses_value, "获取失败")
                                    break
                            else:
                                tijian_data["包块"] = "获取失败"

                            # 包块描述
                            exam_masses_des_input = tree.xpath('//input[@id="examMassesDes"]')[0]
                            if exam_masses_des_input.get('value') == "未查":
                                tijian_data["包块编辑框"] = None
                            else:
                                tijian_data["包块编辑框"] = exam_masses_des_input.get('value')

                        except Exception as e:
                            tijian_data["包块"] = "获取失败"
                            tijian_data["包块编辑框"] = "获取失败"

                        try:
                            # 肝大
                            exam_hepatomegaly_inputs = tree.xpath('//input[@name="EXAM2.examHepatomegaly"]')
                            for input_elem in exam_hepatomegaly_inputs:
                                if 'checked' in input_elem.attrib:
                                    hepatomegaly_value = input_elem.get('value')
                                    hepatomegaly_dict = {
                                        "0": "未检查",
                                        "1": "无",
                                        "2": "有"
                                    }
                                    tijian_data["肝大"] = hepatomegaly_dict.get(hepatomegaly_value, "获取失败")
                                    break
                            else:
                                tijian_data["肝大"] = "获取失败"

                            # 肝大描述
                            exam_hepatomegaly_des_input = tree.xpath('//input[@id="examHepatomegalyDes"]')[0]
                            if exam_hepatomegaly_des_input.get('value') == "未查":
                                tijian_data["肝大编辑框"] = None
                            else:
                                tijian_data["肝大编辑框"] = exam_hepatomegaly_des_input.get('value')

                        except Exception as e:
                            tijian_data["肝大"] = "获取失败"
                            tijian_data["肝大编辑框"] = "获取失败"

                        try:
                            # 脾大
                            exam_splenauxe_inputs = tree.xpath('//input[@name="EXAM2.examSplenauxe"]')
                            for input_elem in exam_splenauxe_inputs:
                                if 'checked' in input_elem.attrib:
                                    splenauxe_value = input_elem.get('value')
                                    splenauxe_dict = {
                                        "0": "未检查",
                                        "1": "无",
                                        "2": "有"
                                    }
                                    tijian_data["脾大"] = splenauxe_dict.get(splenauxe_value, "获取失败")
                                    break
                            else:
                                tijian_data["脾大"] = "获取失败"

                            # 脾大描述
                            exam_splenauxe_des_input = tree.xpath('//input[@id="examSplenauxeDes"]')[0]
                            if exam_splenauxe_des_input.get('value') == "未查":
                                tijian_data["脾大编辑框"] = None
                            else:
                                tijian_data["脾大编辑框"] = exam_splenauxe_des_input.get('value')

                        except Exception as e:
                            tijian_data["脾大"] = "获取失败"
                            tijian_data["脾大编辑框"] = "获取失败"

                        try:
                            # 移动性浊音
                            exam_dullness_inputs = tree.xpath('//input[@name="EXAM2.examDullness"]')
                            for input_elem in exam_dullness_inputs:
                                if 'checked' in input_elem.attrib:
                                    dullness_value = input_elem.get('value')
                                    dullness_dict = {
                                        "0": "未检查",
                                        "1": "无",
                                        "2": "有"
                                    }
                                    tijian_data["移动性浊音"] = dullness_dict.get(dullness_value, "获取失败")
                                    break
                            else:
                                tijian_data["移动性浊音"] = "获取失败"

                            # 移动性浊音描述
                            exam_dullness_des_input = tree.xpath('//input[@id="examDullnessDes"]')[0]
                            if exam_dullness_des_input.get('value') == "未查":
                                tijian_data["移动性浊音编辑框"] = None
                            else:
                                tijian_data["移动性浊音编辑框"] = exam_dullness_des_input.get('value')
                        except Exception as e:
                            tijian_data["移动性浊音"] = "获取失败"
                            tijian_data["移动性浊音编辑框"] = "获取失败"

                        try:
                            # 下肢水肿
                            exam_edema_inputs = tree.xpath('//input[@name="EXAM2.examEdema"]')
                            for input_elem in exam_edema_inputs:
                                if 'checked' in input_elem.attrib:
                                    edema_value = input_elem.get('value')
                                    edema_dict = {
                                        "0": "未检查",
                                        "1": "无",
                                        "2": "单侧",
                                        "3": "双侧不对称",
                                        "4": "双侧对称"
                                    }
                                    tijian_data["下肢水肿"] = edema_dict.get(edema_value, "获取失败")
                                    break
                            else:
                                tijian_data["下肢水肿"] = "获取失败"
                        except Exception as e:
                            tijian_data["下肢水肿"] = "获取失败"

                        try:
                            # 足背动脉搏动
                            exam_dorsalis_pedis_inputs = tree.xpath('//input[@name="EXAM2.examDorsalisPedis"]')
                            for input_elem in exam_dorsalis_pedis_inputs:
                                if 'checked' in input_elem.attrib:
                                    dorsalis_pedis_value = input_elem.get('value')
                                    dorsalis_pedis_dict = {
                                        "0": "未检查",
                                        "1": "未触及",
                                        "2": "触及双侧对称",
                                        "3": "触及左侧弱或消失",
                                        "4": "触及右侧弱或消失",
                                        "5": "无",
                                        "6": "触及双侧弱或消失"
                                    }
                                    tijian_data["足背动脉搏动"] = dorsalis_pedis_dict.get(dorsalis_pedis_value, "获取失败")
                                    break
                            else:
                                tijian_data["足背动脉搏动"] = "获取失败"
                        except Exception as e:
                            tijian_data["足背动脉搏动"] = "获取失败"

                        try:
                            # 肛门指诊
                            exam_dre_inputs = tree.xpath('//input[@name="EXAM2.examDre"]')
                            for input_elem in exam_dre_inputs:
                                if 'checked' in input_elem.attrib:
                                    dre_value = input_elem.get('value')
                                    dre_dict = {
                                        "0": "未检查",
                                        "1": "未及异常",
                                        "2": "触痛",
                                        "3": "包块",
                                        "4": "前列腺异常",
                                        "5": "其他",
                                        "6": "无"
                                    }
                                    tijian_data["肛门指诊"] = dre_dict.get(dre_value, "获取失败")
                                    break
                            else:
                                tijian_data["肛门指诊"] = "获取失败"

                            # 肛门指诊描述
                            exam_dre_des_input = tree.xpath('//input[@id="examDreDes"]')[0]
                            if exam_dre_des_input.get('value') == "未查":
                                tijian_data["肛门指诊编辑框"] = None
                            else:
                                tijian_data["肛门指诊编辑框"] = exam_dre_des_input.get('value')
                        except Exception as e:
                            tijian_data["肛门指诊"] = "获取失败"
                            tijian_data["肛门指诊编辑框"] = "获取失败"
                        if tijian_data["性别"] == "女":
                            try:
                                # 乳腺
                                exam_breast_inputs = tree.xpath('//input[@name="EXAM2.examBreast"]')
                                breast_list = []
                                for input_elem in exam_breast_inputs:
                                    if 'checked' in input_elem.attrib:
                                        breast_value = input_elem.get('value')
                                        breast_dict = {
                                            "1": "未见异常",
                                            "2": "乳房切除",
                                            "3": "异常泌乳",
                                            "4": "乳腺包块",
                                            "5": "其他"
                                        }
                                        breast_list.append(breast_dict.get(breast_value, ""))

                                tijian_data["乳腺"] = ",".join(breast_list) if breast_list else None

                                # 乳腺描述
                                exam_breast_des_input = tree.xpath('//input[@id="examBreastDes"]')[0]
                                if exam_breast_des_input.get('value') == "未查":
                                    tijian_data["乳腺编辑框"] = None
                                else:
                                    tijian_data["乳腺编辑框"] = exam_breast_des_input.get('value')
                            except Exception as e:
                                tijian_data["乳腺"] = "获取失败"
                                tijian_data["乳腺编辑框"] = "获取失败"

                            # 妇科检查信息（仅女性）
                            try:
                                # 外阴
                                exam_vulva_inputs = tree.xpath('//input[@name="EXAM2.examVulva"]')
                                for input_elem in exam_vulva_inputs:
                                    if 'checked' in input_elem.attrib:
                                        vulva_value = input_elem.get('value')
                                        vulva_dict = {
                                            "0": "未检查",
                                            "1": "未见异常",
                                            "2": "异常",
                                            "3": "无"
                                        }
                                        tijian_data["外阴"] = vulva_dict.get(vulva_value, None)
                                        break
                                    else:
                                        tijian_data["外阴"] = None

                                # 外阴描述
                                exam_vulva_des_input = tree.xpath('//input[@id="examVulvaDes"]')[0]

                                tijian_data["外阴编辑框"] = exam_vulva_des_input.get('value')
                                if tijian_data["外阴编辑框"] == "未查":
                                    tijian_data["外阴编辑框"] = None
                            except Exception as e:
                                tijian_data["外阴"] = "获取失败"
                                tijian_data["外阴编辑框"] = "获取失败"

                            try:
                                # 阴道
                                exam_vagina_inputs = tree.xpath('//input[@name="EXAM2.examVagina"]')
                                for input_elem in exam_vagina_inputs:
                                    if 'checked' in input_elem.attrib:
                                        vagina_value = input_elem.get('value')
                                        vagina_dict = {
                                            "0": "未检查",
                                            "1": "未见异常",
                                            "2": "异常",
                                            "3": "无"
                                        }
                                        tijian_data["阴道"] = vagina_dict.get(vagina_value, "获取失败")
                                        break
                                else:
                                    tijian_data["阴道"] = "获取失败"

                                # 阴道描述
                                exam_vagina_des_input = tree.xpath('//input[@id="examVaginaDes"]')[0]
                                tijian_data["阴道编辑框"] = exam_vagina_des_input.get('value')
                                if tijian_data["阴道编辑框"] == "未查":
                                    tijian_data["阴道编辑框"] = None
                            except Exception as e:
                                tijian_data["阴道"] = "获取失败"
                                tijian_data["阴道编辑框"] = "获取失败"

                            try:
                                # 宫颈
                                exam_cervix_inputs = tree.xpath('//input[@name="EXAM2.examCervix"]')
                                for input_elem in exam_cervix_inputs:
                                    if 'checked' in input_elem.attrib:
                                        cervix_value = input_elem.get('value')
                                        cervix_dict = {
                                            "0": "未检查",
                                            "1": "未见异常",
                                            "2": "异常",
                                            "3": "无"
                                        }
                                        tijian_data["宫颈"] = cervix_dict.get(cervix_value, "获取失败")
                                        break
                                else:
                                    tijian_data["宫颈"] = "获取失败"

                                # 宫颈描述
                                exam_cervix_des_input = tree.xpath('//input[@id="examCervixDes"]')[0]
                                tijian_data["宫颈编辑框"] = exam_cervix_des_input.get('value')
                                if tijian_data["宫颈编辑框"] == "未查":
                                    tijian_data["宫颈编辑框"] = None

                            except Exception as e:
                                tijian_data["宫颈"] = "获取失败"
                                tijian_data["宫颈编辑框"] = "获取失败"

                            try:
                                # 宫体
                                exam_corpus_inputs = tree.xpath('//input[@name="EXAM2.examCorpus"]')
                                for input_elem in exam_corpus_inputs:
                                    if 'checked' in input_elem.attrib:
                                        corpus_value = input_elem.get('value')
                                        corpus_dict = {
                                            "0": "未检查",
                                            "1": "未见异常",
                                            "2": "异常",
                                            "3": "无"
                                        }
                                        tijian_data["宫体"] = corpus_dict.get(corpus_value, "获取失败")
                                        break
                                else:
                                    tijian_data["宫体"] = "获取失败"

                                # 宫体描述
                                exam_corpus_des_input = tree.xpath('//input[@id="examCorpusDes"]')[0]
                                tijian_data["宫体编辑框"] = exam_corpus_des_input.get('value')
                                if tijian_data["宫体编辑框"] == "未查":
                                    tijian_data["宫体编辑框"] = None
                            except Exception as e:
                                tijian_data["宫体"] = "获取失败"
                                tijian_data["宫体编辑框"] = "获取失败"

                            try:
                                # 附件
                                exam_adnexa_inputs = tree.xpath('//input[@name="EXAM2.examAdnexa"]')
                                for input_elem in exam_adnexa_inputs:
                                    if 'checked' in input_elem.attrib:
                                        adnexa_value = input_elem.get('value')
                                        adnexa_dict = {
                                            "0": "未检查",
                                            "1": "未见异常",
                                            "2": "异常",
                                            "3": "无"
                                        }
                                        tijian_data["附件"] = adnexa_dict.get(adnexa_value, "获取失败")
                                        break
                                else:
                                    tijian_data["附件"] = "获取失败"

                                # 附件描述
                                exam_adnexa_des_input = tree.xpath('//input[@id="examAdnexaDes"]')[0]
                                tijian_data["附件编辑框"] = exam_adnexa_des_input.get('value')
                                if tijian_data["附件编辑框"] == "未查":
                                    tijian_data["附件编辑框"] = None
                            except Exception as e:
                                tijian_data["附件"] = "获取失败"
                                tijian_data["附件编辑框"] = "获取失败"
                        else:
                            pass
                        # 宫颈涂片其他
                        try:
                            # 宫颈涂片其他
                            exam_other_input = tree.xpath('//input[@id="examOther"]')[0]
                            tijian_data["宫颈涂片其他"] = exam_other_input.get('value')
                        except Exception as e:
                            tijian_data["宫颈涂片其他"] = "获取失败"



                        print("眼底:", tijian_data["眼底"])
                        print("眼底编辑框:", tijian_data["眼底编辑框"])
                        print("皮肤:", tijian_data["皮肤"])
                        print("皮肤编辑框:", tijian_data["皮肤编辑框"])
                        print("巩膜:", tijian_data["巩膜"])
                        print("巩膜编辑框:", tijian_data["巩膜编辑框"])
                        print("淋巴结:", tijian_data["淋巴结"])
                        print("淋巴结编辑框:", tijian_data["淋巴结编辑框"])
                        print("桶状胸:", tijian_data["桶状胸"])
                        print("呼吸音:", tijian_data["呼吸音"])
                        print("呼吸音编辑框:", tijian_data["呼吸音编辑框"])
                        print("罗音:", tijian_data["罗音"])
                        print("罗音编辑框:", tijian_data["罗音编辑框"])
                        print("心率:", tijian_data["心率"])
                        print("心律:", tijian_data["心律"])
                        print("杂音:", tijian_data["杂音"])
                        print("杂音编辑框:", tijian_data["杂音编辑框"])
                        print("压痛:", tijian_data["压痛"])
                        print("压痛编辑框:", tijian_data["压痛编辑框"])
                        print("包块:", tijian_data["包块"])
                        print("包块编辑框:", tijian_data["包块编辑框"])
                        print("肝大:", tijian_data["肝大"])
                        print("肝大编辑框:", tijian_data["肝大编辑框"])
                        print("脾大:", tijian_data["脾大"])
                        print("脾大编辑框:", tijian_data["脾大编辑框"])
                        print("移动性浊音:", tijian_data["移动性浊音"])
                        print("移动性浊音编辑框:", tijian_data["移动性浊音编辑框"])
                        print("下肢水肿:", tijian_data["下肢水肿"])
                        print("足背动脉搏动:", tijian_data["足背动脉搏动"])
                        print("肛门指诊:", tijian_data["肛门指诊"])
                        print("肛门指诊编辑框:", tijian_data["肛门指诊编辑框"])
                        print("乳腺:", tijian_data["乳腺"])
                        print("乳腺编辑框:", tijian_data["乳腺编辑框"])
                        print("外阴:", tijian_data["外阴"])
                        print("外阴编辑框:", tijian_data["外阴编辑框"])
                        print("阴道:", tijian_data["阴道"])
                        print("阴道编辑框:", tijian_data["阴道编辑框"])
                        print("宫颈:", tijian_data["宫颈"])
                        print("宫颈编辑框:", tijian_data["宫颈编辑框"])
                        print("宫体:", tijian_data["宫体"])
                        print("宫体编辑框:", tijian_data["宫体编辑框"])
                        print("附件:", tijian_data["附件"])
                        print("附件编辑框:", tijian_data["附件编辑框"])
                        print("宫颈涂片其他:", tijian_data["宫颈涂片其他"])


                        # 辅助检查
                        # 辅助检查
                        try:
                            # 血常规
                            try:
                                hemoglobin_input = tree.xpath('//input[@id="EXAM3.bloodHemoglobin"]')[0]
                                tijian_data["血红蛋白"] = hemoglobin_input.get('value')
                                if hemoglobin_input.get('value') == "-1.0":
                                    tijian_data["血红蛋白"] = "未查"

                            except:
                                tijian_data["血红蛋白"] = "获取失败"

                            try:
                                leukocyte_input = tree.xpath('//input[@id="EXAM3.bloodWhiteCell"]')[0]
                                tijian_data["白细胞"] = leukocyte_input.get('value')
                                if leukocyte_input.get('value') == "-1.0":
                                    tijian_data["白细胞"] = "未查"
                            except:
                                tijian_data["白细胞"] = "获取失败"

                            try:
                                platelet_input = tree.xpath('//input[@id="EXAM3.bloodPlatelet"]')[0]
                                tijian_data["血小板"] = platelet_input.get('value')
                                if platelet_input.get("value") == "-1.0":
                                    tijian_data["血小板"] = "未查"
                            except:
                                tijian_data["血小板"] = "获取失败"

                            try:
                                exam_blood_des_input = tree.xpath('//input[@id="bloodOther"]')[0]
                                tijian_data["血常规其他"] = exam_blood_des_input.get('value')
                            except:
                                tijian_data["血常规其他"] = "获取失败"

                            # 尿常规
                            try:
                                urine_protein_input = tree.xpath('//input[@id="EXAM3.urineProtein"]')[0]
                                tijian_data["尿蛋白"] = urine_protein_input.get('value')
                                if urine_protein_input.get('value') == "-1":
                                    tijian_data["尿蛋白"] = "未查"
                            except:
                                tijian_data["尿蛋白"] = "获取失败"

                            try:
                                glucose_input = tree.xpath('//input[@id="EXAM3.urineSugar"]')[0]
                                tijian_data["尿糖"] = glucose_input.get('value')
                                if glucose_input.get('value') == "-1":
                                    tijian_data["尿糖"] = "未查"
                            except:
                                tijian_data["尿糖"] = "获取失败"

                            try:
                                urine_acetone_input = tree.xpath('//input[@id="EXAM3.urineKet"]')[0]
                                tijian_data["尿酮体"] = urine_acetone_input.get('value')
                                if urine_acetone_input.get('value') == "-1":
                                    tijian_data["尿酮体"] = "未查"
                            except:
                                tijian_data["尿酮体"] = "获取失败"

                            try:
                                hematuria_input = tree.xpath('//input[@id="EXAM3.urineOccultBlood"]')[0]
                                tijian_data["尿潜血"] = hematuria_input.get('value')
                                if tijian_data["尿潜血"] == "-1":
                                    tijian_data["尿潜血"] = "未查"
                            except:
                                tijian_data["尿潜血"] = "获取失败"

                            try:
                                exam_urine_des_input = tree.xpath('//input[@id="urineOther"]')[0]
                                tijian_data["尿常规其他"] = exam_urine_des_input.get('value')
                            except:
                                tijian_data["尿常规其他"] = "获取失败"

                            # 血糖相关
                            try:
                                fbg_input = tree.xpath('//input[@id="EXAM3.fbg"]')[0]
                                tijian_data["空腹血糖 (mmol/L)"] = fbg_input.get('value')
                                if tijian_data["空腹血糖 (mmol/L)"] == "-1.0":
                                    tijian_data["空腹血糖 (mmol/L)"] = "未查"
                            except:
                                tijian_data["空腹血糖 (mmol/L)"] = "获取失败"

                            try:
                                fbg_mg_input = tree.xpath('//input[@id="EXAM3.fbgMg"]')[0]
                                tijian_data["空腹血糖 (mg/dL)"] = fbg_mg_input.get('value')
                                if tijian_data["空腹血糖 (mg/dL)"] == "-1.0":
                                    tijian_data["空腹血糖 (mg/dL)"] = "未查"
                            except:
                                tijian_data["空腹血糖 (mg/dL)"] = "获取失败"

                            try:
                                hba1c_input = tree.xpath('//input[@id="EXAM3.ghbaic"]')[0]
                                tijian_data["糖化血红蛋白"] = hba1c_input.get('value')
                                if tijian_data["糖化血红蛋白"] == "-1.0":
                                    tijian_data["糖化血红蛋白"] = "未查"
                            except:
                                tijian_data["糖化血红蛋白"] = "获取失败"

                            # 心电图
                            try:
                                ecg_inputs = tree.xpath('//input[@name="EXAM3.electrocardiogram"]')
                                for input_elem in ecg_inputs:
                                    if 'checked' in input_elem.attrib:
                                        ecg_value = input_elem.get('value')
                                        ecg_dict = {
                                            "0": "未检查",
                                            "1": "正常",
                                            "2": "异常",
                                            "3": "无"
                                        }
                                        tijian_data["心电图"] = ecg_dict.get(ecg_value, "获取失败")
                                        break
                                else:
                                    tijian_data["心电图"] = "获取失败"

                                # 心电图描述
                                try:
                                    exam_ecg_des_input = tree.xpath('//input[@id="electrocardiogramDes"]')[0]
                                    tijian_data["心电图编辑框"] = exam_ecg_des_input.get('value')
                                except:
                                    tijian_data["心电图编辑框"] = "获取失败"
                            except:
                                tijian_data["心电图"] = "获取失败"
                                tijian_data["心电图编辑框"] = "获取失败"

                            # 尿微量白蛋白
                            try:
                                malb_input = tree.xpath('//input[@id="EXAM3.microalbuminuria"]')[0]
                                tijian_data["尿微量白蛋白"] = malb_input.get('value')
                                if malb_input.get('value') == "-1.0":
                                    tijian_data["尿微量白蛋白"] = "未查"
                            except:
                                tijian_data["尿微量白蛋白"] = "获取失败"

                            # 大便潜血
                            # 获取大便潜血
                            try:
                                exam_blood_stool_inputs = tree.xpath('//input[@name="EXAM3.examBloodStool"]')
                                for input_elem in exam_blood_stool_inputs:
                                    if 'checked' in input_elem.attrib:
                                        blood_stool_value = input_elem.get('value')
                                        blood_stool_dict = {
                                            "0": "未检查",
                                            "1": "阴性",
                                            "2": "阳性",
                                            "3": "无"
                                        }
                                        tijian_data["大便潜血"] = blood_stool_dict.get(blood_stool_value, "获取失败")
                                        break
                                else:
                                    tijian_data["大便潜血"] = "获取失败"
                            except Exception as e:
                                tijian_data["大便潜血"] = "获取失败"

                            print("大便潜血:", tijian_data["大便潜血"])

                            # 乙型肝炎
                            try:
                                hepatitis_b_inputs = tree.xpath('//input[@name="EXAM3.examHbsag"]')
                                for input_elem in hepatitis_b_inputs:
                                    if 'checked' in input_elem.attrib:
                                        hepatitis_b_value = input_elem.get('value')
                                        hepatitis_b_dict = {
                                            "0": "未检查",
                                            "1": "阴性",
                                            "2": "阳性",
                                            "3": "无"
                                        }
                                        tijian_data["乙型肝炎"] = hepatitis_b_dict.get(hepatitis_b_value, "获取失败")
                                        break
                                else:
                                    tijian_data["乙型肝炎"] = "获取失败"
                            except:
                                tijian_data["乙型肝炎"] = "获取失败"

                            # 肝功能
                            try:
                                sgot_input = tree.xpath('//input[@id="EXAM3.sgot"]')[0]
                                tijian_data["血清谷草转氨酶"] = sgot_input.get('value')
                                if sgot_input.get('value') == "-1.0":
                                    tijian_data["血清谷草转氨酶"] = "未查"
                            except:
                                tijian_data["血清谷草转氨酶"] = "获取失败"

                            try:
                                sgpt_input = tree.xpath('//input[@id="EXAM3.sgpt"]')[0]
                                tijian_data["血清谷丙转氨酶"] = sgpt_input.get('value')
                                if sgpt_input.get('value') == "-1.0":
                                    tijian_data["血清谷丙转氨酶"] = "未查"
                            except:
                                tijian_data["血清谷丙转氨酶"] = "获取失败"

                            try:
                                albumin_input = tree.xpath('//input[@id="EXAM3.albumin"]')[0]
                                tijian_data["白蛋白"] = albumin_input.get('value')
                                if albumin_input.get('value') == '-1.0':
                                    tijian_data["白蛋白"] = "未查"
                            except:
                                tijian_data["白蛋白"] = "获取失败"

                            try:
                                tbil_input = tree.xpath('//input[@id="EXAM3.tbil"]')[0]
                                tijian_data["总胆红素"] = tbil_input.get('value')
                                if tijian_data["总胆红素"] == "-1.0":
                                    tijian_data["总胆红素"] = "未查"
                            except:
                                tijian_data["总胆红素"] = "获取失败"

                            try:
                                dbil_input = tree.xpath('//input[@id="EXAM3.dbil"]')[0]
                                tijian_data["结合胆红素"] = dbil_input.get('value')
                                if dbil_input.get('value') == '-1.0':
                                    tijian_data["结合胆红素"] = "未查"
                            except:
                                tijian_data["结合胆红素"] = "获取失败"

                            # 肾功能
                            try:
                                creatinine_input = tree.xpath('//input[@id="EXAM3.serumCreatinine"]')[0]
                                tijian_data["血清肌酐"] = creatinine_input.get('value')
                                if creatinine_input.get('value') == '-1.0':
                                    tijian_data["血清肌酐"] = "未查"
                            except:
                                tijian_data["血清肌酐"] = "获取失败"

                            try:
                                bun_input = tree.xpath('//input[@id="EXAM3.bun"]')[0]
                                tijian_data["血尿素氮"] = bun_input.get('value')
                                if bun_input.get('value') == '-1.0':
                                    tijian_data["血尿素氮"] = "未查"
                            except:
                                tijian_data["血尿素氮"] = "获取失败"

                            try:
                                potassium_input = tree.xpath('//input[@id="EXAM3.KConsistence"]')[0]
                                tijian_data["血钾浓度"] = potassium_input.get('value')
                                if potassium_input.get('value') == '-1.0':
                                    tijian_data["血钾浓度"] = "未查"
                            except:
                                tijian_data["血钾浓度"] = "获取失败"

                            try:
                                sodium_input = tree.xpath('//input[@id="EXAM3.naConsistence"]')[0]
                                tijian_data["血钠浓度"] = sodium_input.get('value')
                                if sodium_input.get('value') == '-1.0':
                                    tijian_data["血钠浓度"] = "未查"
                            except:
                                tijian_data["血钠浓度"] = "获取失败"

                            # 血脂
                            try:
                                tch_input = tree.xpath('//input[@id="EXAM3.tc"]')[0]
                                tijian_data["总胆固醇"] = tch_input.get('value')
                                if tch_input.get('value') == '-1.0':
                                    tijian_data["总胆固醇"] = "未查"
                            except:
                                tijian_data["总胆固醇"] = "获取失败"

                            try:
                                tg_input = tree.xpath('//input[@id="EXAM3.trig"]')[0]
                                tijian_data["甘油三酯"] = tg_input.get('value')
                                if tg_input.get('value') == '-1.0':
                                    tijian_data["甘油三酯"] = "未查"
                            except:
                                tijian_data["甘油三酯"] = "获取失败"

                            try:
                                ldl_input = tree.xpath('//input[@id="EXAM3.ldl"]')[0]
                                tijian_data["血清低密度脂蛋白胆固醇"] = ldl_input.get('value')
                                if ldl_input.get('value') == "-1.0":
                                    tijian_data["血清低密度脂蛋白胆固醇"] = "未查"
                            except:
                                tijian_data["血清低密度脂蛋白胆固醇"] = "获取失败"

                            try:
                                hdl_input = tree.xpath('//input[@id="EXAM3.hdl"]')[0]
                                tijian_data["血清高密度脂蛋白胆固醇"] = hdl_input.get('value')
                                if hdl_input.get('value') == "-1.0":
                                    tijian_data["血清高密度脂蛋白胆固醇"] = "未查"
                            except:
                                tijian_data["血清高密度脂蛋白胆固醇"] = "获取失败"

                            # 胸部X线片
                            try:
                                xray_chest_inputs = tree.xpath('//input[@name="EXAM3.chestXRay"]')
                                for input_elem in xray_chest_inputs:
                                    if 'checked' in input_elem.attrib:
                                        xray_chest_value = input_elem.get('value')
                                        xray_chest_dict = {
                                            "0": "未检查",
                                            "1": "正常",
                                            "2": "异常",
                                            "3": "无"
                                        }
                                        tijian_data["胸部X线片"] = xray_chest_dict.get(xray_chest_value, "获取失败")
                                        break
                                else:
                                    tijian_data["胸部X线片"] = "获取失败"

                                # 胸部X线片描述
                                try:
                                    exam_xray_chest_des_input = tree.xpath('//input[@id="chestXRayDes"]')[0]
                                    tijian_data["胸部X线片编辑框"] = exam_xray_chest_des_input.get('value')
                                except:
                                    tijian_data["胸部X线片编辑框"] = "获取失败"
                            except:
                                tijian_data["胸部X线片"] = "获取失败"
                                tijian_data["胸部X线片编辑框"] = "获取失败"

                            # 腹部B超
                            # 腹部B超
                            try:
                                b_ultrasound_inputs = tree.xpath('//input[@name="EXAM3.BUltrasonic"]')
                                for input_elem in b_ultrasound_inputs:
                                    if 'checked' in input_elem.attrib:
                                        b_ultrasound_value = input_elem.get('value')
                                        b_ultrasound_dict = {
                                            "0": "未检查",
                                            "1": "正常",
                                            "2": "异常",
                                            "3": "无"
                                        }
                                        tijian_data["腹部B超"] = b_ultrasound_dict.get(b_ultrasound_value, "获取失败")
                                        break
                                else:
                                    tijian_data["腹部B超"] = "获取失败"

                                # 腹部B超描述
                                try:
                                    exam_b_ultrasound_des_input = tree.xpath('//input[@id="BUltrasonicDes"]')[0]
                                    tijian_data["腹部B超编辑框"] = exam_b_ultrasound_des_input.get('value')
                                except:
                                    tijian_data["腹部B超编辑框"] = "获取失败"
                            except:
                                tijian_data["腹部B超"] = "获取失败"
                                tijian_data["腹部B超编辑框"] = "获取失败"


                            # 腹部B超其他
                            try:
                                b_ultrasound_other_inputs = tree.xpath('//input[@name="EXAM3.BUltrasonicOther"]')
                                for input_elem in b_ultrasound_other_inputs:
                                    if 'checked' in input_elem.attrib:
                                        b_ultrasound_other_value = input_elem.get('value')
                                        b_ultrasound_other_dict = {
                                            "0": "未检查",
                                            "1": "正常",
                                            "2": "异常",
                                            "3": "无"
                                        }
                                        tijian_data["腹部B超其他"] = b_ultrasound_other_dict.get(
                                            b_ultrasound_other_value, "获取失败")
                                        break
                                else:
                                    tijian_data["腹部B超其他"] = "获取失败"

                                # 腹部B超其他描述
                                try:
                                    exam_b_ultrasound_other_des_input = \
                                    tree.xpath('//input[@id="BUltrasonicOtherDes"]')[0]
                                    tijian_data["腹部B超其他编辑框"] = exam_b_ultrasound_other_des_input.get('value')
                                except:
                                    tijian_data["腹部B超其他编辑框"] = "获取失败"
                            except:
                                tijian_data["腹部B超其他"] = "获取失败"
                                tijian_data["腹部B超其他编辑框"] = "获取失败"

                            # 宫颈涂片（仅女性）
                            if tijian_data["性别"] == "女":
                                # 宫颈涂片
                                try:
                                    pap_smear_inputs = tree.xpath('//input[@name="EXAM3.papSmear"]')
                                    for input_elem in pap_smear_inputs:
                                        if 'checked' in input_elem.attrib:
                                            pap_smear_value = input_elem.get('value')
                                            pap_smear_dict = {
                                                "0": "未检查",
                                                "1": "正常",
                                                "2": "异常",
                                                "3": "无"
                                            }
                                            tijian_data["宫颈涂片"] = pap_smear_dict.get(pap_smear_value, "获取失败")
                                            break
                                    else:
                                        tijian_data["宫颈涂片"] = None
                                except Exception as e:
                                    tijian_data["宫颈涂片"] = "获取失败"

                                # 宫颈涂片编辑框
                                try:
                                    pap_smear_des_input = tree.xpath('//input[@id="papSmearDes"]')[0]
                                    if pap_smear_des_input.get('value') == "未查":
                                        tijian_data["宫颈涂片编辑框"] = None
                                    else:
                                        tijian_data["宫颈涂片编辑框"] = pap_smear_des_input.get('value')
                                except Exception as e:
                                    tijian_data["宫颈涂片编辑框"] = "获取失败"

                            else:
                                tijian_data["宫颈涂片"] = None
                                tijian_data["宫颈涂片编辑框"] = None

                            # 辅助检查其他
                            try:
                                exam_assist_des_input = tree.xpath('//input[@id="auxiliaryOther"]')[0]
                                tijian_data["辅助检查其他"] = exam_assist_des_input.get('value')
                            except:
                                tijian_data["辅助检查其他"] = "获取失败"

                        except Exception as e:
                            print(f"辅助检查信息获取失败: {e}")

                        print("血红蛋白:", tijian_data["血红蛋白"])
                        print("白细胞:", tijian_data["白细胞"])
                        print("血小板:", tijian_data["血小板"])
                        print("血常规其他:", tijian_data["血常规其他"])
                        print("尿蛋白:", tijian_data["尿蛋白"])
                        print("尿糖:", tijian_data["尿糖"])
                        print("尿酮体:", tijian_data["尿酮体"])
                        print("尿潜血:", tijian_data["尿潜血"])
                        print("尿常规其他:", tijian_data["尿常规其他"])
                        print("空腹血糖 (mmol/L):", tijian_data["空腹血糖 (mmol/L)"])
                        print("空腹血糖 (mg/dL):", tijian_data["空腹血糖 (mg/dL)"])
                        print("心电图:", tijian_data["心电图"])
                        print("心电图编辑框:", tijian_data["心电图编辑框"])
                        print("尿微量白蛋白:", tijian_data["尿微量白蛋白"])
                        print("大便潜血:", tijian_data["大便潜血"])
                        print("糖化血红蛋白:", tijian_data["糖化血红蛋白"])
                        print("乙型肝炎:", tijian_data["乙型肝炎"])
                        print("血清谷丙转氨酶:", tijian_data["血清谷丙转氨酶"])
                        print("血清谷草转氨酶:", tijian_data["血清谷草转氨酶"])
                        print("白蛋白:", tijian_data["白蛋白"])
                        print("总胆红素:", tijian_data["总胆红素"])
                        print("结合胆红素:", tijian_data["结合胆红素"])
                        print("血清肌酐:", tijian_data["血清肌酐"])
                        print("血尿素氮:", tijian_data["血尿素氮"])
                        print("血钾浓度:", tijian_data["血钾浓度"])
                        print("血钠浓度:", tijian_data["血钠浓度"])
                        print("总胆固醇:", tijian_data["总胆固醇"])
                        print("甘油三酯:", tijian_data["甘油三酯"])
                        print("血清低密度脂蛋白胆固醇:", tijian_data["血清低密度脂蛋白胆固醇"])
                        print("血清高密度脂蛋白胆固醇:", tijian_data["血清高密度脂蛋白胆固醇"])
                        print("胸部X线片:", tijian_data["胸部X线片"])
                        print("胸部X线片编辑框:", tijian_data["胸部X线片编辑框"])
                        print("腹部B超:", tijian_data["腹部B超"])
                        print("腹部B超编辑框:", tijian_data["腹部B超编辑框"])
                        print("腹部B超其他:", tijian_data["腹部B超其他"])
                        print("腹部B超其他编辑框:", tijian_data["腹部B超其他编辑框"])
                        print("宫颈涂片:", tijian_data["宫颈涂片"])
                        print("宫颈涂片编辑框:", tijian_data["宫颈涂片编辑框"])
                        print("辅助检查其他:", tijian_data["辅助检查其他"])

                        shifou = ["否","是"]
                        # 获取是否糖尿病
                        diabetes_inputs = tree.xpath('//input[@name="TUBERCULOSIS.isDiabetesMellitus"]')
                        for input_elem in diabetes_inputs:
                            if 'checked' in input_elem.attrib:
                                diabetes_value = input_elem.get('value')
                                break
                        try:
                            tijian_data["是否糖尿病"] = shifou[int(diabetes_value)]
                        except:
                            tijian_data["是否糖尿病"] = None


                        # 获取是否老年人
                        old_inputs = tree.xpath('//input[@name="TUBERCULOSIS.isOld"]')
                        for input_elem in old_inputs:
                            if 'checked' in input_elem.attrib:
                                old_value = input_elem.get('value')
                                break
                        try:
                            tijian_data["是否老年人"] = shifou[int(old_value)]
                        except:
                            tijian_data["是否老年人"] = None

                        # 肺结核可疑症状
                        try:
                            # 是否咳嗽、咳痰≥2周
                            is_cough_inputs = tree.xpath('//input[@name="TUBERCULOSIS.isCough"]')
                            for input_elem in is_cough_inputs:
                                if 'checked' in input_elem.attrib:
                                    is_cough_value = input_elem.get('value')
                                    if is_cough_value == "1":
                                        tijian_data["是否咳嗽、咳痰≥2周"] = "是"
                                    elif is_cough_value == "0":
                                        tijian_data["是否咳嗽、咳痰≥2周"] = "否"
                                    break
                            else:
                                tijian_data["是否咳嗽、咳痰≥2周"] = "获取失败"
                        except Exception as e:
                            tijian_data["是否咳嗽、咳痰≥2周"] = "获取失败"

                        try:
                            # 是否痰中带血或咯血
                            is_hemoptysis_inputs = tree.xpath('//input[@name="TUBERCULOSIS.isHemoptysis"]')
                            for input_elem in is_hemoptysis_inputs:
                                if 'checked' in input_elem.attrib:
                                    is_hemoptysis_value = input_elem.get('value')
                                    if is_hemoptysis_value == "1":
                                        tijian_data["是否痰中带血或咯血"] = "是"
                                    elif is_hemoptysis_value == "0":
                                        tijian_data["是否痰中带血或咯血"] = "否"
                                    break
                            else:
                                tijian_data["是否痰中带血或咯血"] = "获取失败"
                        except Exception as e:
                            tijian_data["是否痰中带血或咯血"] = "获取失败"

                        print("是否糖尿病:",tijian_data["是否糖尿病"])
                        print("是否老年人:", tijian_data["是否老年人"])
                        print("是否咳嗽、咳痰≥2周:", tijian_data["是否咳嗽、咳痰≥2周"])
                        print("是否痰中带血或咯血:", tijian_data["是否痰中带血或咯血"])

                        #
                        # 获取脑血管疾病信息
                        try:
                            cerebrovascular_inputs = tree.xpath('//input[@name="EXAM3.cerebrovascular"]')
                            cerebrovascular_list = []
                            cerebrovascular_des = ""

                            for input_elem in cerebrovascular_inputs:
                                if 'checked' in input_elem.attrib:
                                    value = input_elem.get('value')
                                    # 根据value值确定具体疾病
                                    cerebrovascular_dict = {
                                        "1": "未发现",
                                        "2": "缺血性卒中",
                                        "3": "脑出血",
                                        "4": "蛛网膜下腔出血",
                                        "5": "短暂性脑缺血",
                                        "6": "其他"
                                    }
                                    if value == "6":
                                        # 获取其他描述
                                        cerebrovascular_des_input = tree.xpath('//input[@id="cerebrovascularDes"]')[0]
                                        cerebrovascular_des = cerebrovascular_des_input.get('value')
                                        cerebrovascular_list.append(f"其他:{cerebrovascular_des}")
                                    else:
                                        cerebrovascular_list.append(cerebrovascular_dict.get(value, ""))

                            tijian_data["脑血管疾病"] = ",".join(cerebrovascular_list) if cerebrovascular_list else "未发现"
                            tijian_data["脑血管疾病编辑框"] = cerebrovascular_des
                        except Exception as e:
                            tijian_data["脑血管疾病"] = "获取失败"
                            tijian_data["脑血管疾病编辑框"] = "获取失败"

                        # 获取肾脏疾病信息
                        try:
                            nephropathy_inputs = tree.xpath('//input[@name="EXAM3.nephropathy"]')
                            nephropathy_list = []
                            nephropathy_des = ""

                            for input_elem in nephropathy_inputs:
                                if 'checked' in input_elem.attrib:
                                    value = input_elem.get('value')
                                    # 根据value值确定具体疾病
                                    nephropathy_dict = {
                                        "1": "未发现",
                                        "2": "糖尿病肾病",
                                        "3": "肾功能衰竭",
                                        "4": "急性肾炎",
                                        "5": "慢性肾炎",
                                        "6": "其他"
                                    }
                                    if value == "6":
                                        # 获取其他描述
                                        nephropathy_des_input = tree.xpath('//input[@id="nephropathyDes"]')[0]
                                        nephropathy_des = nephropathy_des_input.get('value')
                                        nephropathy_list.append(f"其他:{nephropathy_des}")
                                    else:
                                        nephropathy_list.append(nephropathy_dict.get(value, ""))

                            tijian_data["肾脏疾病"] = ",".join(nephropathy_list) if nephropathy_list else "未发现"
                            tijian_data["肾脏疾病编辑框"] = nephropathy_des
                        except Exception as e:
                            tijian_data["肾脏疾病"] = "获取失败"
                            tijian_data["肾脏疾病编辑框"] = "获取失败"

                        # 获取心脏疾病信息
                        try:
                            heart_disease_inputs = tree.xpath('//input[@name="EXAM3.heartDisease"]')
                            heart_disease_list = []
                            heart_disease_des = ""

                            for input_elem in heart_disease_inputs:
                                if 'checked' in input_elem.attrib:
                                    value = input_elem.get('value')
                                    # 根据value值确定具体疾病
                                    heart_disease_dict = {
                                        "1": "未发现",
                                        "2": "心肌梗死",
                                        "3": "心绞痛",
                                        "4": "冠状动脉血运重建",
                                        "5": "充血性心力",
                                        "6": "心前区疼痛",
                                        "7": "其他"
                                    }
                                    if value == "7":
                                        # 获取其他描述
                                        heart_disease_des_input = tree.xpath('//input[@id="heartDiseaseDes"]')[0]
                                        heart_disease_des = heart_disease_des_input.get('value')
                                        heart_disease_list.append("其他")
                                    else:
                                        heart_disease_list.append(heart_disease_dict.get(value, ""))

                            tijian_data["心脏疾病"] = ",".join(heart_disease_list) if heart_disease_list else "未发现"
                            tijian_data["心脏疾病编辑框"] = heart_disease_des
                        except Exception as e:
                            tijian_data["心脏疾病"] = "获取失败"
                            tijian_data["心脏疾病编辑框"] = "获取失败"

                        # 获取血管疾病信息
                        try:
                            vascular_inputs = tree.xpath('//input[@name="EXAM3.vascular"]')
                            vascular_list = []
                            vascular_des = ""

                            for input_elem in vascular_inputs:
                                if 'checked' in input_elem.attrib:
                                    value = input_elem.get('value')
                                    # 根据value值确定具体疾病
                                    vascular_dict = {
                                        "1": "未发现",
                                        "2": "夹层动脉瘤",
                                        "3": "动脉闭塞性疾病",
                                        "4": "其他"
                                    }
                                    if value == "4":
                                        # 获取其他描述
                                        vascular_des_input = tree.xpath('//input[@id="vascularDes"]')[0]
                                        vascular_des = vascular_des_input.get('value')
                                        vascular_list.append(f"其他:{vascular_des}")
                                    else:
                                        vascular_list.append(vascular_dict.get(value, ""))

                            tijian_data["血管疾病"] = ",".join(vascular_list) if vascular_list else "未发现"
                            tijian_data["血管疾病编辑框"] = vascular_des
                        except Exception as e:
                            tijian_data["血管疾病"] = "获取失败"
                            tijian_data["血管疾病编辑框"] = "获取失败"

                        # 获取眼部疾病信息
                        try:
                            eye_disease_inputs = tree.xpath('//input[@name="EXAM3.eyeDisease"]')
                            eye_disease_list = []
                            eye_disease_des = ""

                            for input_elem in eye_disease_inputs:
                                if 'checked' in input_elem.attrib:
                                    value = input_elem.get('value')
                                    # 根据value值确定具体疾病
                                    eye_disease_dict = {
                                        "1": "未发现",
                                        "2": "视网膜出血或渗出",
                                        "3": "视乳头水肿",
                                        "4": "白内障",
                                        "5": "其他"
                                    }
                                    if value == "5":
                                        # 获取其他描述
                                        eye_disease_des_input = tree.xpath('//input[@id="eyeDiseaseDes"]')[0]
                                        eye_disease_des = eye_disease_des_input.get('value')
                                        eye_disease_list.append(f"其他:{eye_disease_des}")
                                    else:
                                        eye_disease_list.append(eye_disease_dict.get(value, ""))

                            tijian_data["眼部疾病"] = ",".join(eye_disease_list) if eye_disease_list else "未发现"
                            tijian_data["眼部疾病编辑框"] = eye_disease_des
                        except Exception as e:
                            tijian_data["眼部疾病"] = "获取失败"
                            tijian_data["眼部疾病编辑框"] = "获取失败"

                        # 获取神经系统疾病信息
                        try:
                            nerve_sys_inputs = tree.xpath('//input[@name="EXAM3.nerveSys"]')
                            nerve_sys_value = ""
                            nerve_sys_des = ""

                            for input_elem in nerve_sys_inputs:
                                if 'checked' in input_elem.attrib:
                                    value = input_elem.get('value')
                                    nerve_sys_dict = {
                                        "1": "未发现",
                                        "2": "有"
                                    }
                                    nerve_sys_value = nerve_sys_dict.get(value, "")
                                    if value == "2":
                                        # 获取描述
                                        nerve_sys_des_input = tree.xpath('//input[@id="nerveSysDes"]')[0]
                                        nerve_sys_des = nerve_sys_des_input.get('value')
                                    break

                            tijian_data["神经系统疾病"] = nerve_sys_value
                            tijian_data["神经系统疾病编辑框"] = nerve_sys_des
                        except Exception as e:
                            tijian_data["神经系统疾病"] = "获取失败"
                            tijian_data["神经系统疾病编辑框"] = "获取失败"

                        # 获取其他系统疾病信息
                        try:
                            other_sys_inputs = tree.xpath('//input[@name="EXAM3.otherSys"]')
                            other_sys_value = ""
                            other_sys_des = ""

                            for input_elem in other_sys_inputs:
                                if 'checked' in input_elem.attrib:
                                    value = input_elem.get('value')
                                    other_sys_dict = {
                                        "1": "未发现",
                                        "2": "有"
                                    }
                                    other_sys_value = other_sys_dict.get(value, "")
                                    if value == "2":
                                        # 获取描述
                                        other_sys_des_input = tree.xpath('//input[@id="otherSysDes"]')[0]
                                        other_sys_des = other_sys_des_input.get('value')
                                    break

                            tijian_data["其他系统疾病"] = other_sys_value
                            tijian_data["其他系统疾病编辑框"] = other_sys_des
                        except Exception as e:
                            tijian_data["其他系统疾病"] = "获取失败"
                            tijian_data["其他系统疾病编辑框"] = "获取失败"

                        # 打印获取的结果
                        print("脑血管疾病:", tijian_data["脑血管疾病"])
                        print("脑血管疾病编辑框:", tijian_data["脑血管疾病编辑框"])
                        print("肾脏疾病:", tijian_data["肾脏疾病"])
                        print("肾脏疾病编辑框:", tijian_data["肾脏疾病编辑框"])
                        print("心脏疾病:", tijian_data["心脏疾病"])
                        print("心脏疾病编辑框:", tijian_data["心脏疾病编辑框"])
                        print("血管疾病:", tijian_data["血管疾病"])
                        print("血管疾病编辑框:", tijian_data["血管疾病编辑框"])
                        print("眼部疾病:", tijian_data["眼部疾病"])
                        print("眼部疾病编辑框:", tijian_data["眼部疾病编辑框"])
                        print("神经系统疾病:", tijian_data["神经系统疾病"])
                        print("神经系统疾病编辑框:", tijian_data["神经系统疾病编辑框"])
                        print("其他系统疾病:", tijian_data["其他系统疾病"])
                        print("其他系统疾病编辑框:", tijian_data["其他系统疾病编辑框"])


                        #
                        # 获取评价信息
                        try:
                            exam_assessment_inputs = tree.xpath('//input[@name="EXAM3.examAssessment"]')
                            exam_assessment_value = ""
                            exam_assessment_des = ""

                            for input_elem in exam_assessment_inputs:
                                if 'checked' in input_elem.attrib:
                                    value = input_elem.get('value')
                                    exam_assessment_dict = {
                                        "1": "体检无异常",
                                        "2": "有异常"
                                    }
                                    exam_assessment_value = exam_assessment_dict.get(value, "")
                                    if value == "2":
                                        # 获取异常描述
                                        exam_assessment_des_input = tree.xpath('//textarea[@id="examAssessmentDes"]')[0]
                                        exam_assessment_des = exam_assessment_des_input.get('value')
                                    break

                            tijian_data["评价"] = exam_assessment_value
                            tijian_data["评价编辑框"] = exam_assessment_des
                        except Exception as e:
                            tijian_data["评价"] = "获取失败"
                            tijian_data["评价编辑框"] = "获取失败"

                        try:
                            exam_assessment_des_input = tree.xpath('//textarea[@id="examAssessmentDes"]')
                            if exam_assessment_des_input:
                                tijian_data["评价编辑框"] = exam_assessment_des_input[0].text
                            else:
                                tijian_data["评价编辑框"] = "未找到元素"
                        except Exception as e:
                            tijian_data["评价编辑框"] = "获取失败"

                        # 获取指导信息
                        try:
                            exam_guidance_inputs = tree.xpath('//input[@name="EXAM3.examGuidance"]')
                            exam_guidance_list = []

                            for input_elem in exam_guidance_inputs:
                                if 'checked' in input_elem.attrib:
                                    value = input_elem.get('value')
                                    exam_guidance_dict = {
                                        "1": "纳入慢性病患者健康管理",
                                        "2": "建议复查",
                                        "3": "建议转诊"
                                    }
                                    exam_guidance_list.append(exam_guidance_dict.get(value, ""))

                            tijian_data["指导"] = ",".join(exam_guidance_list) if exam_guidance_list else None
                        except Exception as e:
                            tijian_data["指导"] = "获取失败"

                        # 获取危险因素控制信息
                        try:
                            exam_ctrl_inputs = tree.xpath('//input[@name="EXAM3.examCtrl"]')
                            exam_ctrl_list = []

                            for input_elem in exam_ctrl_inputs:
                                if 'checked' in input_elem.attrib:
                                    value = input_elem.get('value')
                                    exam_ctrl_dict = {
                                        "1": "戒烟",
                                        "2": "健康饮酒",
                                        "3": "饮食",
                                        "4": "锻炼",
                                        "5": "减体重(kg)目标",
                                        "8": "减腰围(cm)目标",
                                        "6": "建议接种疫苗",
                                        "7": "其他"
                                    }
                                    exam_ctrl_list.append(exam_ctrl_dict.get(value, ""))

                            tijian_data["危险因素控制"] = ",".join(exam_ctrl_list) if exam_ctrl_list else "无"

                            # 获取危险因素控制的详细信息
                            # 减体重(kg)目标编辑框
                            try:
                                exam_ctrl_weight_input = tree.xpath('//input[@id="examCtrlWeight"]')[0]
                                tijian_data["减体重(kg)目标编辑框"] = exam_ctrl_weight_input.get('value')
                            except Exception as e:
                                tijian_data["减体重(kg)目标编辑框"] = "获取失败"

                            # 减腰围(cm)目标编辑框
                            try:
                                exam_ctrl_waistline_input = tree.xpath('//input[@id="examCtrlWaistline"]')[0]
                                tijian_data["减腰围(cm)目标编辑框"] = exam_ctrl_waistline_input.get('value')
                            except Exception as e:
                                tijian_data["减腰围(cm)目标编辑框"] = "获取失败"

                            # 建议接种疫苗
                            try:
                                exam_ctrl_vaccin_input = tree.xpath('//input[@id="examCtrlVaccin"]')[0]
                                tijian_data["建议接种疫苗编辑框"] = exam_ctrl_vaccin_input.get('value')
                            except:
                                tijian_data["建议接种疫苗编辑框"] = ""

                            # 其他
                            try:
                                exam_ctrl_des_input = tree.xpath('//input[@id="examCtrlDes"]')[0]
                                tijian_data["危险因素控制其他编辑框"] = exam_ctrl_des_input.get('value')
                            except:
                                tijian_data["危险因素控制其他编辑框"] = ""

                        except Exception as e:
                            tijian_data["危险因素控制"] = "获取失败"
                            tijian_data["减体重(kg)目标编辑框"] = "获取失败"
                            tijian_data["减腰围(cm)目标编辑框"] = "获取失败"
                            tijian_data["建议接种疫苗编辑框"] = "获取失败"
                            tijian_data["危险因素控制其他编辑框"] = "获取失败"

                        # 建议编辑框
                        try:
                            exam_suggestion_input = tree.xpath('//textarea[@id="examSuggestion"]')
                            if exam_suggestion_input:
                                # 使用 .text 获取 textarea 的内容
                                tijian_data["建议编辑框"] = exam_suggestion_input[0].text.strip() if \
                                exam_suggestion_input[0].text else ""
                            else:
                                tijian_data["建议编辑框"] = ""
                        except Exception as e:
                            tijian_data["建议编辑框"] = "获取失败"

                        print("建议编辑框:", tijian_data["建议编辑框"])

                        # 打印获取的结果
                        print("评价:", tijian_data["评价"])
                        print("评价编辑框:", tijian_data["评价编辑框"])
                        print("指导:", tijian_data["指导"])
                        print("危险因素控制:", tijian_data["危险因素控制"])
                        print("减体重(kg)目标编辑框:", tijian_data["减体重(kg)目标编辑框"])
                        print("减腰围(cm)目标编辑框:", tijian_data["减腰围(cm)目标编辑框"])
                        print("建议接种疫苗编辑框:", tijian_data["建议接种疫苗编辑框"])
                        print("危险因素控制其他编辑框:", tijian_data["危险因素控制其他编辑框"])
                        print("建议编辑框:", tijian_data["建议编辑框"])
                        all_infomation.append(tijian_data)
        return all_infomation
    except:
        print(f"处理失败: {id_number}, 错误: 获取信息时报错了")
        return None


if __name__ == "__main__":
    id_number = "110229194904141648"
    ehrid = "33c5c78a-649f-4b52-8807-80a3630e3e26"
    COOKIE = "A9F2E8BAE32007FADD2A8C36570A8634"
    DOMAIN = "http://10.174.166.48:8082"
    start_limit_time = "2025-01-01"
    end_limit_time = "2025-10-01"


    print(tijiandownload(id_number, ehrid, {
                "cookie": f"JSESSIONID={COOKIE}",
            }, DOMAIN,start_limit_time, end_limit_time))
